Loading local jquery.js file in node js

I want to load a local jquery file into my node js chat.I application I searched a lot, but I can not find a suitable solution.

<!doctype html> <html> <head> <title>Socketio</title> </head> <body> <!--This wont work --> <script src="/socket.io/jquery.min.js"></script> <!--This will work --> <script src="/socket.io/socket.io.js"></script> </body> </html> 

I just copy the jquery.js file to the socket.io folder. The socket.io.js file loads correctly, but the jquery didnt file. Please help me. Here is my index.js file

 var app = require('express')(); var server = require('http').Server(app); var io = require('socket.io')(server); app.get('/', function(req, res){ res.sendFile(__dirname + '/index.html'); }); server.listen(3000, function(){ console.log('listening on *:3000'); }); 
+5
source share
5 answers

Finally, I found the answer. I just download the jquery file from localhost this way http://localhost/assets/jquery.min.js .

+1
source

You might want to let the Express platform render HTML and transfer static jQuery files. This is how I do it.

This page explains how you can restructure your application for working with jquery files using node routes instead of HTML code.

0
source
 app.get('/jquery', function(res, req){ res.sendFile(__dirname + '/jquery.js'); }); 
0
source
 app.use('/assets', express.static('assets')) 

Put your jquery.min.js file in the relative path "/assets/jquery.min.js", then access as http: //localhost/assets/jquery.min.js

"localhost" could also be your IP address.

Personally, I need this because I need a completely independent demonstration in order to work regardless of the available Internet connection. Murphy's Law is alive and well suited for a conference.

0
source

One way to solve the problem is to use a link to the source file on the Internet. Try loading jquery with the following,

 <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

This works great in the end.

-1
source

Source: https://habr.com/ru/post/1209845/


All Articles