Petter Sunde Petter Sunde - 9 months ago 53
Node.js Question

Including node modules on my page

What's the best way of including a node module on my webpage?

Should I use absolute paths like

<script src="../../node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
or is there an easier and better way of doing it?

Thank you.


Add this in your app.js-file

app.use('/placeholder', express.static(__dirname + '/node_modules/'));

This allows you to write:

<script src="/placeholder/bootstrap/dist/js/bootstrap.min.js"></script>

And Node will redirect that path to the node_modules folder.

You can change placeholder to whatever you want, mine is named scripts