Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to link to JavaScript file in node_modules?

I want to link to /node_modules/jade/runtime.min.js client-side -- how do I make it publicly accessible?

Do I create a app.get for it somehow?

app.get('/js/jade-runtime.js',<what goes here?>)

Or can I modify the static thing to allow it to be served?

app.use(express.static(path.join(__dirname, 'public'))); // modify this to add more paths somehow

Full solution (thanks Brad):

app.get('/js/jade-runtime.js',function(req,res) {
    res.sendfile(path.join(__dirname,'node_modules','jade','runtime.min.js'));
});
like image 666
mpen Avatar asked Dec 31 '12 04:12

mpen


1 Answers

You can use this with your app.get.

res.sendfile('jade-runtime.js');

Obviously, use the correct path to where that file is located.

http://expressjs.com/api.html#res.sendfile

like image 102
Brad Avatar answered Oct 10 '22 03:10

Brad