gpt4 book ai didi

node.js - 如何链接到 node_modules 中的 JavaScript 文件?

转载 作者:搜寻专家 更新时间:2023-10-31 22:44:02 25 4
gpt4 key购买 nike

我想链接到 /node_modules/jade/runtime.min.js 客户端——如何让它公开访问?

我是否以某种方式为它创建一个 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

完整解决方案(感谢 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');

显然,使用该文件所在位置的正确路径。

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

关于node.js - 如何链接到 node_modules 中的 JavaScript 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14097408/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com