Reputation: 8233
That's surely a noob question, but the thing is : how can I easily include JS libs to the front-end part of a Node (with Socket.io) app ?
What I did in my HTML file :
<script src="libs/hammer.js"></script>
This HTML file is handled by Node :
app.get('/', function(request, response){
response.sendFile(__dirname + '/index.html');
});
So, as expected, the client can't find http://127.0.0.1:3000/libs/hammer.js
(assuming I'm running locally on port 3000) : it returns a 404 on that request.
Should I handle those libs with node_modules ? or something else ? I'm pretty lost on that question.
Upvotes: 0
Views: 143
Reputation: 32127
Assuming you're using express, you need to serve them with express.static
.
Add this to your middleware stack:
app.use('/libs', express.static(__dirname + '/libs'));
Upvotes: 1