My steps to change the default port:
- react-native start --port 9999.
- react-native run-android.
- change the port in the app.
Is there an easy way?
My steps to change the default port:
Is there an easy way?
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 :
....
module.exports = {
name: 'start',
func: server,
description: 'starts the webserver',
options: [{
command: '--port [number]',
default: 8081, //change to 9999
parse: (val: string) => Number(val),
},
....
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 run npm start
or yarn start
then no need to change anything just run yarn start
and your code automatically run on 8082
.
Note:-
8082
with your port number.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).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