Petter Sunde Petter Sunde - 1 year ago 93
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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download