Search code examples
node.jsexpresslan

NodeJS - Server access from outside/LAN IP is failed


I made a demo app using ExpressJS.

Accessing API through POSTMAN in the system works fine. But I can not access the same with my mobile browser, where both Mobile and Server system are connected to same wifi.

My server.js code:

const express = require('express');
const bodyParser = require('body-parser');
const app = express();

app.listen(3000, "0.0.0.0", function() {
    console.log("Listening on Port 3000");
});

app.get('/server/identify', function(req, res) {
    console.log(req.body);
    var data = {
        "meta": {
            "status": "success",
            "message": "Server is running"
        }
    };
    res.json(data);
});

Solution

  • You will need to expose port 3000 on your local network and then access the machine using it's local network IP address. No one will be able to access it unless the port is open on your machine.

    Take a look at something like ngrok, this should handle exposing a port for you and make it accessible to anyone you give the link as long as they're connected to the internet. This might help you build your application and test it quickly on your machine and mobile before deploying it.