Home > front end >  Express.JS server to connect to host on remote network
Express.JS server to connect to host on remote network

Time:11-24

So I got this small express server running. I can connect it to other devices on my local network e.g. mobile and other PC. However when connecting over my 4g it does not work. Is there any reason for this? I am sure when I ping other private addresses on remote networks it has worked before, why not now?

Code:

const express = require("express");
const server = express();
const PORT = 3000

server.use(express.static("static"));

server.get("/", (req,res)=>{
    res.sendFile(__dirname    "/pages/index.html")
});

server.listen(PORT, "0.0.0.0", (req,res) => {
    console.log("Listening on port ", PORT)
});

Any information would be apricated I have some networking experience (still a noob just studying) and this really does interest me.

CodePudding user response:

I assume you are trying to reach the server via your local IP. But you are doing it with 4G (in your phone maybe), which means your request is going over the internet while your local IP is only valid in your network.

Even if you are using your public IP, you would probably have to configure port forwarding on your router for it to know how to handle the incoming traffic for this port.

CodePudding user response:

If you host your express server in your private network , you must have access to the express server by create port forwarding, destination nat, or some kind of publishing private services to public world methods.

If you need more help , i need to know more about your network env , your public ip and ...

Feel free to ask An have a productive day

  • Related