简体   繁体   中英

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'));
});

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM