Search code examples
node.jsjson-server

Can't connect to json-server from another device


I installed the json-server from https://github.com/typicode/json-server and works fine, I can execute GET, POST etc., but locally only. When I try to connect from the outside it doesn't work.

I tried to turn off firewall, change ports and diffrent startup settings (i.e json-server --host 192.168.0.21 db.json) and nothing helped. Here's my database.


[
  {
    "id": 2,
    "login": "admin3",
    "haslo": "haslo3"
  },
  {
    "id": 3,
    "login": "admin2",
    "haslo": "haslo2"
  },
  {
    "login": "admin1",
    "haslo": "haslo1",
    "id": 7
  }
]

I would like to be able to connect to my server from the whole world, but only local adresses work (i.e http://192.168.0.21:3000/user or http://localhost:3000/user). What's wrong with my approach?


Solution

  • Make sure you are starting the server bound to your adapter (ex. --host 0.0.0.0).

    Then you need to setup port forwarding on your router.

    https://deaddesk.top/exposing-local-server-to-the-public-internet/