Take the 2-minute tour ×

Is there any way to reference a Nodejs library included in node_modules folder from a ejs view?

I'm using expressjs and my client libraries are served form /public folder as depicted below, so I'm not being able to reach the node_modules folder from a ejs view

share|improve this question
add comment

1 Answer


Using requirejs, it seems you can serve modules directly from node_modules. See the documentation on requirejs and node.


var requirejs = require('requirejs');

    nodeRequire: require

requirejs(['some_module'], function(some_module) {
    // Here, some_module will be loaded from your node_modules

Old answer:

You can use app.locals in express to expose properties or functions to your views.

See the example from the docs (linked above):

app.locals.title = 'My App';
app.locals.strftime = require('strftime');
share|improve this answer
yes, I know but I'd rather want to access to the file. As an include from the view like <script src="my-nodejs-module.js">, actually I'm using requirejs on the client side so I want to reference that library from my main.js file –  user1796747 Nov 15 '12 at 15:03
Oh, you want to serve it to the client? You should clarify your question, I think -- it reads as if you want to use it in the ejs template. –  Linus G Thiel Nov 15 '12 at 16:24
add comment

Your Answer


