Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Cannot GET /index.html

my project directory is -

app
├── app.js
├── index.html
├── node_modules
├── package.json
├── package-lock.json
├── signup_success.html
└── style.css

my app file code are given below-

app.js file code:-

var express=require("express");
var bodyParser=require("body-parser");
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/gfg');
var db=mongoose.connection;
db.on('error', console.log.bind(console, "connection error"));
db.once('open', function(callback){
 console.log("connection succeeded");
})
var app=express()
app.use(bodyParser.json());
app.use(express.static('public'));
//app.use(express.static(__dirname + "/../public"));
//app.use(app.router);
app.use(bodyParser.urlencoded({
 extended: true
}));
app.post('/sign_up', function(req,res){
 var name = req.body.name;
 var email =req.body.email;
 var pass = req.body.password;
 var phone =req.body.phone;
 var data = {
 "name": name,
 "email":email,
 "password":pass,
 "phone":phone
 }
db.collection('details').insertOne(data,function(err, collection){
 if (err) throw err;
 console.log("Record inserted Successfully");
 
 });
 
 return res.redirect('signup_success.html');
})
app.get('/',function(req,res){
res.set({
 'Access-control-Allow-Origin': '*'
 });
return res.redirect('index.html');
}).listen(3000)
console.log("server listening at port 3000");

when I am running the app.js file then I am getting "Cannot GET /index.html" on the browser?

Answer*

Draft saved
Draft discarded
Cancel
1
  • 1
    I have got the message "Cannot GET /index.html" because I was not providing the correct path of the HTML file. now after resolving it my project directory look like this- app ├── app.js ├── node_modules ├── package.json ├── package-lock.json └── public ├── index.html ├── signup_success.html └── style.css Thank you I have resolved my issue. Commented Nov 14, 2021 at 19:40

default

AltStyle によって変換されたページ (->オリジナル) /