javascript – JS file gets a net::ERR_ABORTED 404 (Not Found)

javascript – JS file gets a net::ERR_ABORTED 404 (Not Found)

As mentionned in comments: you need a way to send your static files to the client. This can be achieved with a reverse proxy like Nginx, or simply using express.static().

Put all your static (css, js, images) files in a folder dedicated to it, different from where you put your views (html files in your case). Ill call it static for the example. Once its done, add this line in your server code:

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

This will effectively serve every file in your static folder via the /static route.

Querying your index.js file in the client thus becomes:

<script src=static/index.js></script>

I had a similar issue that was resolved by omitting the leading slashes in my code. E.g. replace /js/script.js with js/script.js.

javascript – JS file gets a net::ERR_ABORTED 404 (Not Found)

Leave a Reply

Your email address will not be published.