close

[Solved] JS file gets a net::ERR_ABORTED 404 (Not Found)

Hello Guys, How are you all? Hope You all Are Fine. Today I am just run my simple web socket project But I am facing following error JS file gets a net::ERR_ABORTED 404 (Not Found) in Javascript. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How JS file gets a net::ERR_ABORTED 404 (Not Found) Error Occurs ?

Today I am just run my simple web socket project But I am facing the following error

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

Here is my html file.

<script src="/socket.io/socket.io.js"></script>
<script src="https://code.jquery.com/jquery-1.11.1.js"></script>
<script src="index.js"></script>
</body>
</html>

Here is my server.js file

app.get('/', function(req, res){
  res.sendFile(__dirname + '/index.html');
});

How To Solve JS file gets a net::ERR_ABORTED 404 (Not Found) Error ?

  1. How To Solve JS file gets a net::ERR_ABORTED 404 (Not Found) Error?

    To Solve JS file gets a net::ERR_ABORTED 404 (Not Found) Error Here we 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). I'll call it static for the example. Once it's done, add this line in your server code:

  2. JS file gets a net::ERR_ABORTED 404 (Not Found)

    To Solve JS file gets a net::ERR_ABORTED 404 (Not Found) Error Here we 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). I'll call it static for the example. Once it's done, add this line in your server code:

Solution 1

Here we 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). I’ll call it static for the example. Once it’s 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>

Solution 2

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also Read

Please Rate Our Solution to Motivate Us For Give Our Best

Leave a Comment