Search code examples
javascriptangularjsnode.jsexpresswebserver

expressjs Cannot GET/ error, can not reach to any file in other folders


I am just trying to create a very simple server with expressJS , just to get data for my Angular application but I couldnt find any solution for that error, which is displayed in the browser ' Cannot GET/ ' .

The code of webserver I tried to create ;

var express = require('express');
var path = require('path');

var app = express();

var rootPath = path.normalize(__dirname + '/../');

app.use(express.static(rootPath + '/app'));

app.listen(8000);

console.log('Listening on port 8000  ');

basically what I am trying to do is when i visit the localhost:8000/EventDetails.html the page should be shown. ( this is why I am using /../)


Solution

  • You need to specify path for static content:

    app.use('/', express.static(path.normalize(__dirname + '/../app')))