There's no doubting Nextjs as a powerful framework for building production-grade, hybrid web applications.
Sometimes, when building responsive applications, it is very important to be able to test on mobile and other devices in real-time. create-react-app
does this out of the box, with next, we need to follow a few steps.
(It is important to note that for this to work, all the devices you want to test on have to be connected to the same network.)
- Open your terminal and run the command
ipconfig
for windows orifconfig
for MacBooks. You'll see the network you're currently connected to, the IPv4 address being the current local IP address.
Now to the deployment.
On your terminal, run yarn dev -H [your IP address]
or npm run dev -H [your IP address]
. For example, yarn dev -H 102.168.8.100
. This creates a server with your application hosted on your local IP address, and the link shows up on your terminal using the default port of 3000, or any port you configured your app to run on.
That link can then be used on any device, and any changes you make to your app will be updated in real-time.
Happy Building!
Top comments (4)
very helpful! thanks a lot
That's useful thank you
thx. but how do I switch back to local hosting?
Hi. Just run
yarn dev
on another terminal window or cancel the current deploy and run the dev command.