如何链接到node_modules中的JavaScript文件?
我想链接到/node_modules/jade/runtime.min.js
客户端 – 我如何使它公开可访问?
我以某种方式创build一个app.get
吗?
app.get('/js/jade-runtime.js',<what goes here?>)
或者我可以修改静态的东西,让它被送达?
app.use(express.static(path.join(__dirname, 'public'))); // modify this to add more paths somehow
完整的解决scheme(感谢Brad ):
app.get('/js/jade-runtime.js',function(req,res) { res.sendfile(path.join(__dirname,'node_modules','jade','runtime.min.js')); });
你可以使用你的app.get
。
res.sendfile('jade-runtime.js');
很显然,使用正确的path到文件所在的位置。