I have installed jquery with npm (npm install jquery --save) and it added jquery to my node_modules folder. What path do I use for the script tag on the html page?
Here is what my directory structure looks like (only included what is necessary)
-Project Root
-node_modules
-jquery
-dist
-jquery.js
-src
-index.js
-index.html
-package.json
For socket.io it looks like this
<script src="/socket.io/socket.io.js"></script>
I tried this for jquery but it didn't work
<script src="/jquery/dist/jquery.js"></script>
Any help will be greatly appreciated! Thanks!
You don't need to install a jQuery node module to run jQuery on the client side. You should be able to just load it from a public or static directory. For example,
Your project Structure
-Project Root
-public
-js
jquery.js
-node_modules
-index.js
-index.html
-package.json
HTML
<!doctype html>
<html>
<head>
<script src="/socket.io/socket.io.js"></script>
<script src="public/js/jquery.js"></script>
</head>
<body>
... stuff ...
</body>
</html>
app.js
I am assuming you are using Express, like what is recommended in the Socket.IO getting started example. http://socket.io/get-started/chat/ So in your app.js you need to declare your public or static location. This will allow your index.html to access the files from within that folder.
app.use('/public', express.static('public'));
Express serving static:
http://expressjs.com/starter/static-files.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With