如何从 IPad 连接到本地网络 NodeJS 服务器?

How connect from IPad to a local network NodeJS Server?

我想使用本地网络从我的 IPad 连接到安装在我的 Windows OS 系统上的 运行 NodeJS 服务器。

有什么方法可以连接这个或本地网络中的其他设备吗?

我目前正在使用 xip.io 但我没有得到任何结果。

我通过后续步骤获得了它:

  1. 安装以下 NPM 包 - Minihost globally using npm install -g minihost. It may require the graceful-fs 包更新。

  2. 我用下一个示例代码创建了一个 server.js 文件:

    const express = require("express");
    const bodyParser = require("body-parser");
    const path = require("path");
    //const minihost = require("minihost");

    const server = express();

    const host = process.env.host || "127.0.0.1";
    const port = process.env.port || 2000;

    server.set('views', './app/views');
    server.set('view engine', 'jade');

    server.use(bodyParser.urlencoded({extended: true}));
    server.use(bodyParser.json());

    server.get("/", (req, res) => res.render("home"));
    server.listen(port, host, () => console.log(`Listening on http://${host}:${port}`))
  1. 使用一些示例代码创建视图 app\views\home.jade

  2. 在您的 CLI 界面中执行下一条命令:

    h -- node server.js //Don't forget prefix with h -- your node server command
  1. 执行,如果你在WindowsOS机器cmd命令ipconfig获取本机IP

  2. 下一个 URL:

    http://node-xip-io.YOUR-LOCAL-IP.xip.io:2000 //i.e. http://node-xip-io.192.168.0.102.xip.io:2000

Don't forget replace YOUR-LOCAL-IP with the IP you got with the ipconfig cli command.