简体   繁体   English

Express 应用程序无法在没有互联网的本地网络上运行

[英]Express app not working on local network without internet

I have an express app with which I want other computers in the same WIFI Network to connect to it but without the internet being available.我有一个快速应用程序,我希望同一 WIFI 网络中的其他计算机连接到它,但没有可用的互联网。

The main PC which is hosting the app has the following fixed IP: 192.168.1.60托管应用程序的主 PC 具有以下固定 IP:192.168.1.60

And I have done the following code in my server.js我在 server.js 中完成了以下代码

app.listen(5000, '192.168.1.60' () => {
  console.log(`Server launched with port 5000`);
});

So whenever I try to access the app from another machine, it does not load unless I have internet.因此,每当我尝试从另一台机器访问该应用程序时,除非我有互联网,否则它不会加载。

Is there a way to make it work without the internet?有没有办法让它在没有互联网的情况下工作?

app.get('/', (req, res) => {
  res.send('Hello User!')
})
app.listen(5000, () => {
  console.log(`Server launched with port ${port}`)
})

Make sure you enter following URL http://192.168.1.60:5000 in your browser确保在浏览器中输入以下 URL http://192.168.1.60:5000

When you say "without internet" - I'm going to assume that means that your devices are connected to the same local network but that there is no further connection via an ISP.当您说“没有互联网”时 - 我假设这意味着您的设备连接到同一个本地网络,但没有通过 ISP 进一步连接。

This should have no effect whatsoever on accessing your local server.这对访问本地服务器应该没有任何影响

Provided that the connection to your server machine (192.168.1.60) functions from another device on your network by going to http://192.168.1.60:5000 then there will be no difference when there is no internet accessible via your network.如果通过转到http://192.168.1.60:5000从您网络上的另一台设备连接到您的服务器计算机(192.168.1.60),那么当您的网络无法访问互联网时不会有任何区别。 Please provide more information as to what you mean by "without internet" and how you are testing this.请提供更多信息,说明“没有互联网”的含义以及您如何测试它。

You must ensure that:您必须确保:

  • Each device has an assigned IP on the network and can access the network每台设备在网络上都有一个分配的IP,可以访问网络
  • No "host isolation" features are enabled on your switch/router您的交换机/路由器上没有启用“主机隔离”功能
  • Your server device (192.168.1.60) does not have a firewall blocking the connection您的服务器设备 (192.168.1.60) 没有阻止连接的防火墙

I don't have enough reputation to comment, so had to post this answer - please provide more details and I can help more我没有足够的声誉来发表评论,所以不得不发布这个答案 - 请提供更多详细信息,我可以提供更多帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM