javascript - 访问本地主机:3000 through localhost/myproject/index. html

标签 javascript node.js express socket.io localhost

我是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/

相关文章:

javascript - 我可以在 JavaScript 中使用变量作为变量名吗?

node.js - 使用 Jimp 将图像放在其他图像上

mysql - 快速重定向错误 : can't set headers after they are sent using NodeJS and MySQL

javascript - 如何使用 node.js Cheerio 一个一个地获取元素

express - 通过 paypal 快速结账定期订阅,买家支付两次

node.js - Kraken.js CSRF 处理

mongodb - 如何通过 id - mongoose 删除嵌套集合中的项目

javascript - 在javascript中添加多个元素

javascript - `.toPrecision()`方法怎么知道PI的16°、17°、18°数字呢?

javascript - Symfony 中缓慢/低效的 Javascript 代码开发周期