Petter Sunde Petter Sunde - 4 months ago 16
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.

Answer

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

Comments