Next.js Discord

Discord Forum

Trying to view localhost on phone hosted my laptop

Answered
Peterbald posted this in #help-forum
Open in Discord
PeterbaldOP
Hey there. I'm trying to use my phone (Android) to load my localhost environment thar's being hosted on my computer. I'm using Next 13.4.1 and I'm not sure if there's something that I need to enable. Both devices are on the same Wi-fi network. I found my local IP.

Is there anything that I need to enable or set up? Thanks! 🙂
Answered by Peterbald
I figured it out. I'm using Nrwl and didn't think to consider it's project.json or hostname variable workaround.

@Rhinoceros Auklet was right, but with different syntax

nx serve <appname> --hostname 0.0.0.0


Thanks, all!
View full answer

17 Replies

PeterbaldOP
Thanks for replying!

Does it have to be :3000? I have another older Next project that works fine under :3000, but not this one. The newer project runs under :4200 on my machine.
@Peterbald Thanks for replying! Does it have to be :3000? I have another older Next project that works fine under :3000, but not this one. The newer project runs under :4200 on my machine.
then just substitute the port

if on computer you can access it at localhost:12345 then on your phone you can access it at <computer ip>:12345
same for any port
PeterbaldOP
Hmm. Still no luck. This should be working out of the box.
Dunker
@Peterbald there is a thing like yourip:port for mobiles. i was accessing with that
but you should use wifi to access that port
PeterbaldOP
It should, you're right.
I might have something blocking it via my WiFi settings , but another Next project that I use works via my phone.
Dunker
now i tried it on mine
my pc on ethernet, and mobile on wifi
i wrote my ip to chrome and port
worked
you can always use ngrok
if theres some issue with your local wifi
Rhinoceros Auklet
npm start --host 0.0.0.0
PeterbaldOP
I figured it out. I'm using Nrwl and didn't think to consider it's project.json or hostname variable workaround.

@Rhinoceros Auklet was right, but with different syntax

nx serve <appname> --hostname 0.0.0.0


Thanks, all!
Answer