C Luo C Luo - 1 year ago 97
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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download