Error running express with node Error running express with node express express

Error running express with node


That is because you are passing "/" as second parameter (options)

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

See serve-static:

function serveStatic(root, options) ...

https://github.com/expressjs/serve-static/blob/master/index.js

Also note that it would be better to use a different directory than your root e.g. express.static(__dirname + '/public') to avoid exposing your root.


express.static is used to define directory where your "static" files reside look at here for more info.

It accepts only a string with the path you want to be static:

So your code should be:

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

Or

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

But that doesn't make much sense, imho.

Remove the line or define the real path where your assets files are.


The second parameter you are passing to express.static is incorrect. remove the second parameter.app.use(express.static(__dirname));