0

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.

1 Answer 1

1

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'));
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I totally miss that point. I'll check Express doc about that. That's working fine right now :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.