C Luo C Luo - 4 months ago 12x
Node.js Question

The index page of Node.js does not read css or javascript files

It runs on Mac.

All files are in Library/WebServer/Documents/.

When I run node index.js, the code returns: {

Failed to load resource: the server responded with a status of 404 (Not Found)


However, if I open the html file, it reads everything.

What is the ugly bug behind?


You should inclued these resource before using them.

You can do it as : app.use(express.static(__dirname + '/public'));

'public'is folder where you will have static content like images/JS/CSS.

For more information visit : http://expressjs.com/en/starter/static-files.html