我是node.js的新手,我想了解是否可以通过编写index.html的url来访问node.js端口(3000)。我关注了this tutorial创建一个聊天应用程序,但我遇到了上面提到的问题。
我希望能够在浏览器上编写 localhost/myproject/index.html 而不是 localhost:3000。
我的服务器端 JavaScript 代码是这样的:
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
http.listen(3000, function(){
console.log('listening on *:3000');
});
这里有什么我应该改变的吗?任何帮助将不胜感激。
最佳答案
如果您想以域名而不是 localhost:3000 运行项目,则只需点击此链接即可 https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts
关于javascript - 访问本地主机:3000 through localhost/myproject/index. html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44216285/