Getting 404 for local files in Node.js

44 Views Asked by At

I recently posted Background image not showing with CSS and thought it has to be something with the url I included even though I was sure it was correct (they were in the same directory so it was straightforward). I wasn't able to resolve that issue and now, I face the same issue but for a .js file.

Picture of work space:

enter image description here

Picture of the Run prompt:

enter image description here .

In app.js I do have require('./like_button');. I am new to using these technologies, I must be missing something general...

1

There are 1 best solutions below

0
On BEST ANSWER

You have to serve the static file from a specific folder. In your case views.

Add this line where you've declared your app.

app.use(express.static('views'))

For more reference check out

http://expressjs.com/en/starter/static-files.html