我怎样才能使node.js服务器在局域网而不是本地主机上监听我的IP [英] How can i make a node.js server to listen to my ip on my lan instead of localhost

查看:379
本文介绍了我怎样才能使node.js服务器在局域网而不是本地主机上监听我的IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于expressjs和node.js构建的网站,该网站在我的本地主机上运行良好.我如何才能使其在我的ip(192.168.69.100)而不是localhost上运行,以便局域网上的其他用户可以访问它.

先谢谢了. :)

我的代码段

app.listen(port,function (err) {
if(err)
{
    console.log(err);
}

console.log('Running on ' + port);
});

解决方案

默认情况下,节点将在运行它的主机公开的每个IP地址上运行.您不需要做任何特别的事情.您已经知道服务器在特定端口上运行.您可以通过在该计算机上的浏览器中使用该IP地址来证明这一点:

http://192.168.69.100:port

如果这不起作用,则可能是您的IP地址有误.

I have a website built on top of expressjs and node.js which is running fine on my localhost. How can i make it to run on my ip(192.168.69.100) instead of localhost so that other users on my LAN can access it.?

Thanks in advance. :)

A snippet of my code

app.listen(port,function (err) {
if(err)
{
    console.log(err);
}

console.log('Running on ' + port);
});

解决方案

By default node will run on every IP address exposed by the host on which it runs. You don't need to do anything special. You already knew the server runs on a particular port. You can prove this, by using that IP address on a browser on that machine:

http://192.168.69.100:port

If that didn't work, you might have your IP address wrong.

这篇关于我怎样才能使node.js服务器在局域网而不是本地主机上监听我的IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆