-2

Windows OS システムにインストールされている実行中の NodeJS サーバーに、ローカル ネットワークを使用して IPad から接続したいと考えています。

このデバイスまたは他のデバイスをローカル ネットワークに接続する方法はありますか?

現在 xip.io を使用していますが、結果が得られませんでした。

4

1 に答える 1

0

次の手順を使用して取得しました。

  1. を使用して、次の NPM パッケージ - Minihostをグローバルにインストールしますnpm install -g minihostgraceful-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. Windows OS マシンを使用している場合は、cmd コマンドipconfigを実行して、ローカル マシンの IP を取得します。

  2. デバイスに次の URL を入力します。

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

YOUR-LOCAL-IPipconfigをcli コマンドで取得した IP に置き換えることを忘れないでください。

于 2016-05-15T22:48:31.317 に答える