NodeJS w/Express Error: Cannot GET /
You typically want to render templates like this:
app.get('/', function(req, res){
res.render('index.ejs');
});
However you can also deliver static content - to do so use:
app.use(express.static(__dirname + '/public'));
Now everything in the /public
directory of your project will be delivered as static content at the root of your site e.g. if you place default.htm
in the public folder if will be available by visiting /default.htm
Take a look through the express API and Connect Static middleware docs for more info.
You need to define a root route.
app.get('/', function(req, res) {
// do something here.
});
Oh and you cannot specify a file within the express.static
. It needs to be a directory. The app.get('/'....
will be responsible to render that file accordingly. You can use express' render method, but your going to have to add some configuration options that will tell express where your views are, traditionally within the app/views/
folder.