3

I'm trying to host my app on 0.0.0.0:3000 and not localhost.

However each time I run the nx serve career --port=3000 --host=0.0.0.0

The app is hosted on:

tcp6 0 0 :::3000 :::* LISTEN 9112/node

Instead of:

tcp6 0 0 0.0.0.0:3000 0 0.0.0.0:* LISTEN 9112/node

the difference is ::: instead of 0.0.0.0.

What am I doing wrong, how can I host the app on 0.0.0.0

I'm using nrwl/nx and NextJS even if the port is correct the host is not.

Salman
  • 1,109
  • 3
  • 25
  • 55

5 Answers5

5

By default, the program will launch at http://localhost:3000. The default port can be modified by using -p, as in npx next dev -p 4000, or by using PORT, as in PORT=4000 npx next dev.

In terms of altering the hostname. You can also change the hostname from the default of 0.0.0.0. -H can be used to alter the default hostname, as in npx next dev -H 192.168.1.2.

Find this and more from the NextJS official blog on Development

So in your case, it should be

npx next dev -H 0.0.0.0 -p 3000

Sorry, I'm using npm/npx instead of nx.

cigien
  • 57,834
  • 11
  • 73
  • 112
Dev_Michael
  • 71
  • 1
  • 9
1

and you can use this IP

127.0.0.1:3000
  • Doesn't work either. – Salman Nov 23 '21 at 14:07
  • it should work I use this IP for run localhost – Seyed Kazem Mousavi Nov 23 '21 at 15:32
  • Although 0.0.0.0 and 127.0.0.1 often play the same role, they are [not the same thing](https://stackoverflow.com/a/20778887/2227743). You cannot blindly change one for the other in all situations - well, you cannot, at least, expect that it would magically solve the issue everytime. – Eric Aya Nov 23 '21 at 19:13
1

--host=0.0.0.0 is an option for @nrwl/js:node

For a @nrwl/next:server executor you can use the options hostname like nx serve career --port=3000 --hostname=0.0.0.0.

You should see the logs like

web-1  |
web-1  | > nx run web:serve:development --hostname=0.0.0.0
web-1  |
web-1  | info  - automatically enabled Fast Refresh for 1 custom loader
web-1  | event - compiled client and server successfully in 2.1s (166 modules)
web-1  | [ ready ] on http://0.0.0.0:4200
web-1  | wait  - compiling / (client and server)...
web-1  | event - compiled client and server successfully in 362 ms (172 modules)
web-1  | wait  - compiling /_error (client and server)...
web-1  | event - compiled client and server successfully in 423 ms (173 modules)
Ike Chang
  • 74
  • 1
  • 5
0

For connecting other devices for debugging, make sure both devices are connected to same network (WiFi).

  • Search for the ip address of the network you are connected, In my case I'm using Mac, you can enter this command in the terminal :
    ipconfig getifaddr en0

  • In your Nextjs project run the project in this way:
    npm run dev -- -H /your_ip_address/
    for example - npx next dev -H 192.168.1.2

Your's may be a different one.
Explore more on - NextJS docs

Happy coding :)

Hafiz
  • 61
  • 4
-1

It's Working on my Laptop so you can try it http://127.0.0.1:3000/

Exampele = https://prnt.sc/obXNMHuWU5sq

Al-Mamun
  • 9
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 03 '22 at 08:21