简体   繁体   English

使用 express 在 LAN 上打开 node.js 服务器

[英]Open a node.js server on LAN using express

Okay so I've just started studying node.js, and it's gotten to the point in which I want to acces the website from my phone, but none of the solutions online are working for me.好的,所以我刚刚开始研究 node.js,它已经到了我想从我的手机访问该网站的地步,但没有一个在线解决方案对我有用。

I'm starting the web server like this:我正在启动 web 服务器,如下所示:

const express = require('express');

// Express app
const app = express();

// Set view engine
app.set('view engine', 'ejs');

// Listen for requests
app.listen(3000);

//Just some routing example
app.get('/', (req, res) => {
res.render('index', { title: 'Home', blogs})
});

I have tried changing "app.listen(3000);"我试过改变“app.listen(3000);” for "app.listen(3000, 'ANY IP THAT APPEARED IN CMD IPCONFIG');"对于“app.listen(3000,'任何出现在 CMD IPCONFIG'中的 IP');”

As you may have guessed, it didn't work either.正如您可能已经猜到的那样,它也不起作用。

I'm pretty lost in all of this, and I need your help.我迷失在这一切中,我需要你的帮助。

Thanks!谢谢!

To have Express open to your LAN you need to make sure your ports are open on your router.要让 Express 对您的 LAN 开放,您需要确保您的端口在您的路由器上打开。 From what I understand you are able to start the server and connect on your computer but you want to see it on your phone.据我了解,您可以启动服务器并在您的计算机上连接,但您想在手机上看到它。 That is less of an Express issue and more of "making sure your ports and IP are correct on your router".这不是 Express 问题,更多的是“确保您的端口和 IP 在您的路由器上是正确的”。 Typically routers block ports for protection reasons.通常,出于保护原因,路由器会阻止端口。

There is also a similar question here which might also help you with how the port forwarding etc. works for Express and how to solve it. 这里还有一个类似的问题,它也可以帮助您了解端口转发等如何适用于 Express 以及如何解决它。

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

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