我用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));
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句