node.js服务器是否需要Internet连接才能运行? [英] Does node.js server need internet connection to run?

查看:41
本文介绍了node.js服务器是否需要Internet连接才能运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我禁用Internet连接并运行节点服务器 npm start ,然后抛出错误:

I disable the internet connection and run the node server npm start, then it throws the error:

现在启用Internet连接并运行服务器可以正常工作:

And now enabling internet connection and running the server works fine:

因此,我想确认启动服务器时是否真的需要将其连接到互联网吗?

So, I want to confirm if this really needs to be connected to the internet while starting the server?

如果确实需要Internet连接,那么是否有任何想法可以离线运行服务器?

If it really needs internet connection, then is there any idea to run the server offline?

如果我连接到Internet并运行服务器,并且在拔出Internet连接之后在那里,则没有任何问题.一切正常.我不知道为什么仅运行服务器就需要Internet连接.

If I connect to the internet and run the server and there after plug out the internet connection then there's nothing goes wrong. Everything works fine. I don't know why just running the server requires the internet connection.

推荐答案

OMG!这个真的很酷!经过认真研究代码后,我使用 127.0.0.1 代替mongo uri的 localhost 使其脱机工作.

OMG! It's really cool! I got it working offline after hard research in my code using 127.0.0.1 instead of localhost for mongo uri.

使用我需要连接到Internet的 localhost .

Using localhost needed for me to connect to the internet.

使用 127.0.0.1 可以在两种情况下(即可以连接互联网和不可以连接互联网)工作.

And using 127.0.0.1 worked in both condition i.e. with internet connection and without internet connection.

但是,真的,我对此感到非常惊奇.

But, really I'm totally amazed of this.

我发现了真正的很酷的主题在这上让我对此很清楚.

I found the really cool topic on this which made me clear about this.

如果您使用127.0.0.1,那么(智能)软件将直接将其直接转换为IP地址并使用它.

If you use 127.0.0.1, then (intelligent) software will just turn that directly into an IP address and use it.

并且不能保证您的主机文件将实际用于该分辨率(首先或根本不使用),因此localhost可能成为完全不同的IP地址.

And there's no guarantee that your hosts file will actually be used for that resolution (first, or at all) so localhost may become a totally different IP address.

这篇关于node.js服务器是否需要Internet连接才能运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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