Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GET http://localhost:3000/insert.js net::ERR_ABORTED 404 (Not Found)

I'm a beginner at web dev, I'm currently working on a project, but the javascript file insert.js won't load. The html document, upload.html is inside the public folder, and the javascript is inside the main folder. I used the following path to link the javascript file,

<script src= "../insert.js"></script>

But it didn't seem to work, so I then tried moving upload.html to the main folder, which is HR and I used the following code,

<script src = "/insert.js"></script>

And this didn't work either, so I then tried moving insert.js to the public folder, and used the same path as I have mentioned above, but, then I couldn't export variables to app.js which is located in the main HR directory.

The image I have attached shows location of the files

I don't get what could possibly cause this, I think I should mention this as well, but I got an error while running my javascript file in node. So I inserted the following code in node_modules/whatwg-url/dist/encoding.js:

const {TextDecoder, TextEncoder} = require("util");

I don't know if this has anything to do with my issue, but I thought I would just mention it.

like image 725
srish Avatar asked Nov 21 '25 19:11

srish


1 Answers

localhost can only access your public folder, so you have to move insert.js in the public folder and do:

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

Also if you have node modules in that javascript file it wont run because it can't run the modules and you would have to use a bundler for that js file like webpack, rollup or snowpack.

like image 104
FurrySenko Avatar answered Nov 23 '25 07:11

FurrySenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!