如果我在 node.js 中有一个 httpserver,它在端口 3000 上为网站提供服务。
var httpserver = http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
app.get('/', function(req, res) {
res.render('index.html');
});
我需要访问位于/public/的txt文件
例如,如果我执行 localhost:3000/other_site.html,如果此 other_site.html 位于/public/中,则会打开它,但如果文件是 txt,则不会打开它。
是否有无需安装 http-request、connect 或其他 npm 模块即可解决此问题的解决方案?
问候,
最佳答案
可以用 express 吗?如果是,
app.use(express.static(__dirname + '/public'))
成功了。
如果没有,请尝试搜索文件:) Using node.js as a simple web server
关于javascript - node.js http 在浏览器中打开静态文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26493744/