我用express编写了一个nodeJS服务器,我希望它能够传递index.html和引用的main.js。它只提供index.html,两个文件位于同一目录中:
app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});
最佳答案
除了 index.html
之外,它不提供其他文件。
如果您想在目录中提供静态文件,最简单的解决方案是使用express.static
:
app.use (express.static(__dirname));
关于javascript - nodeJS - Express 应提供引用的 main.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21049942/