Arne Claassen
Arne Claassen

Reputation: 14404

How to serve node_module files to the client

I'm trying to figure out of if there is a feature or convention I'm missing for referencing a js file from a node_module in the client html via script. For example, I have underscore installed via npm and use it on the server side, but also want to use underscore-min.js in the client. Right now i symlink the file into my expressjs static folder, but that seem hacky.

Is there an official or at least cleaner way?

Upvotes: 3

Views: 531

Answers (2)

Marco
Marco

Reputation: 1511

underscore-min.js really has nothing to do with node. It's a distributed file for serving to clients. My advice is to copy it out of the module into any static serving location you want. It may feel hacky to have 2 copies of the same file, but it's not. You may even want them to be updated separately.

Upvotes: 0

alessioalex
alessioalex

Reputation: 63653

You can try browserify and put all your js files (Node modules) in a folder, for more details checkout his awesome article:

http://substack.net/posts/24ab8c/browserify-browser-side-require-for-your-node-js

Upvotes: 4

Related Questions