node.jsipadlocal-network

How connect from IPad to a local network NodeJS Server?


I'd like to connect to a running NodeJS Server installed on my Windows OS System from my IPad using the local network.

Is there any way to connect this or other devices in the local network?

I'm currently using xip.io but I didn't get any result.


Solution

  • I got it using the next steps:

    1. Install the following NPM Package - Minihost globally using npm install -g minihost. It may require the graceful-fs package update.

    2. I create a server.js file with the next sample code:

        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. Create the view app\views\home.jade with some sample code.

    2. Execute the next command in your CLI interface:

        h -- node server.js //Don't forget prefix with h -- your node server command
    
    1. Execute, if you are in Windows OS Machine the cmd command ipconfig to get the IP of your local machine.

    2. Put in your device the next 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.