1
votes

I created a simple web page using nodejs platform , html and jquery . After running my code , I got this error

http://localhost:3000/js/jquery.min.js Failed to load resource: the server responded with a status of 404 (Not Found)

Any suggested solutions ?

1

1 Answers

1
votes

Simple solution, get jquery from a CDN.

<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>

Second solution is to configure nodejs to have a public folder and there to keep your public files. (if you use express packace)

app.use(express.static(__dirname + "/js"));

And access the file in this way: <script src="/jquery.min.js"></script>


I recomment you to have public folder and there to keep your javascript and css files.

app.use(express.static(__dirname + "/public"));

Inside that folder create a structure like this

--public
   --css
      -> example.css
   --js
      -> jquery-2.1.3.min.js

Add script and link tags according

<link href="/css/example.css" rel="stylesheet" />
<script src="/js/jquery-2.1.3.min.js"></script>

And access js/css files like this

http://www.example.com/js/jquery.min.js 
http://www.example.com/css/example.css