How to open a create-react-app from another comput

2020-05-21 11:41发布

I am using create-react-app and hosting in its default port localhost:3000 and want to access this from another device on the same network.

I got the IP of my host's IP (using ifconfig) 192.168.0.5 and tried opening 192.168.0.5:3000 but that did not work.

Is there any way to achieve this?

4条回答
霸刀☆藐视天下
2楼-- · 2020-05-21 11:49

Simply run HOST=0.0.0.0 npm run start.
Afterwards open the url from another device on the network.

In your case, 192.168.0.5:3000 would work.

Documentation for setting HOST environment variables.

查看更多
劫难
3楼-- · 2020-05-21 11:55

Can you please turn off your firewall and check 192.168.0.5:3000.

Thanks

查看更多
贼婆χ
4楼-- · 2020-05-21 12:05

In my case, npm run start used my Ethernet adapter's IP e.g. http://192.168.167.113:3000 but as I was accessing the site using WLAN, I needed to use WLAN IP which was 192.168.0.227.

Make sure to use WLAN IP with the same port to make it work.

查看更多
疯言疯语
5楼-- · 2020-05-21 12:11

As I can't post comment, In complementary to Elad if you have react-scripts start instead of npm run start

HOST=0.0.0.0 react-scripts start

Works too !

查看更多
登录 后发表回答