You can also change permanent the port with change default server in react native node modules your_app\node_modules\react-native\local-cli\server\server.js and change the port 8081 to 9999 like this :
Update your port of your react-native project by below commands. just save below code in file can be named as update-port and run this file by /file/path/update-portat your react-native project level (Where you run npm start or yarn start then no need to change anything just run yarn start and your code automatically run on 8082.
Note:-
You can directly run below command at project level.
you can also update port number replace 8082 with your port number.
For Android you need to set port in dav setting/Debug Server host & port for device then set port like 127.1.0.0:8082 (first your ip and then use your port).
When ever your update your node-module the default port will automatically change then please re-run update-port file.
#!/bin/bash
sed -i '' 's/8081/8082/g' ./node_modules/react-native/local-cli/server/server.js
sed -i '' 's/8081/8082/g' ./node_modules/react-native/React/Base/RCTBridgeDelegate.h
sed -i '' 's/8081/8082/g' ./node_modules/react-native/React/Base/RCTDefines.h
sed -i '' 's/8081/8082/g' ./node_modules/react-native/React/DevSupport/RCTInspectorDevServerHelper.mm
sed -i '' 's/8081/8082/g' ./node_modules/react-native/React/React.xcodeproj/project.pbxproj
sed -i '' 's/8081/8082/g' ./node_modules/react-native/local-cli/runIOS/runIOS.js
sed -i '' 's/8081/8082/g' ./node_modules/react-native/local-cli/util/isPackagerRunning.js
sed -i '' 's/8081/8082/g' ./node_modules/react-native/local-cli/runAndroid/runAndroid.js
sed -i '' 's/8081/8082/g' ./node_modules/react-native/Libraries/RCTTest/RCTTestRunner.m
You can also change permanent the port with change default server in react native node modules
your_app\node_modules\react-native\local-cli\server\server.js
and change the port 8081 to 9999 like this :I hope this answer can help you :)
Update your port of your react-native project by below commands. just save below code in file can be named as
update-port
and run this file by/file/path/update-port
at your react-native project level (Where you runnpm start
oryarn start
then no need to change anything just runyarn start
and your code automatically run on8082
.Note:-
8082
with your port number.dav setting/Debug Server host & port for device
then set port like127.1.0.0:8082
(first your ip and then use your port).update-port
file.