ReactNative port 8081 issue : 403 Forbidden - javascript

While developing using ReactNative on Windows, I am getting below 403 error. This is because port 8081 which ReactNative uses by default is being used by another program. In my case it was McAfee (Thanks McAfee for making this harder).
Command to run the project : react-native run-android

I searched around a lot and finally figured out how to run this project on a different port. If you have any Antivirus software installed then it may help if you disable the firewall while developing or allow connections manually through settings.
Start ReactNative on a different port
react-native start --port 9080
This will open a new command prompt and start the metro bundler on port 9080 (you can use any other port you want). Wait for the dependency graph to be fully loaded.
Now in a different command prompt (project directory) use the below command to build and install the app on device
react-native run-android
Now once the app is loaded on device you will see the 403 error along with the red screen. To make the device communicate on a different port use below command.
adb reverse tcp:8081 tcp:9080
or if you have multiple device connected then provide the device id (e.g. FA6AA0301277)
adb -s FA6AA0301277 reverse tcp:8081 tcp:9080
To know the list of devices connected use below command
adb devices
That's it, now you should be able to see the index page :)
Happy Coding :)

Related

localhost:3000 is not working in the browser

Backend: Express server, with npx create-express-api backend
Frontend: Next.js, with npx create-react-app frontend
I have implemented these command in my root folder and trying to run npm start xxx to check if they are still working or not. But they are not working in my http://localhost:3000
Though they are working in this link http://172.27.178.192:3000 (on my network)
This is the image showing the problem
I have changed browsers and still the same problem is appearing. On the browser it says
Unable to connect
Firefox can’t establish a connection to the server at localhost:3000.
netstat -ano | findstr :8080
Then the PID will appear at the right which you can kill with taskkill.
The last number the pid.
then:
taskkill/pid 11704 /F
How to close TCP and UDP ports via windows command line
I think some other application occupied your 3000 port. try find which one is. If you have found then closed and try again.
For instance you want to free the port 3000 Then, follow these commands.
netstat -ano
taskkill /f /im [PID of the port 3000 got from previous command]
How to close TCP and UDP ports via windows command line
in browser history search for localhost:3000 and delete all of them.
make sure you closed all terminalls(check vscode too) and all tabs in your browsers.
in new widnows terminal npx kill-port 3000 do it in WSL2 terminall too.
make sure your firewall is turn of.
restart you computer.
It worked for me
Delete the .next folder ( if your working on nextjs ) and try npm run dev command OR
Move the project to another folder location OR
Take back up of the code and delete the project and then run the same project again
You can try all of the above also

Move my MERN app (developped on windows) on a ubuntu machine and access it via LAN network

It's my first time here so please bear with me :)
Basically i developped a full stack MERN web application on my windows 10 machine (node js, express js and Mongodb in the backend + database and react js for the frontend), to run each one of them for now i use vscode (nodemon server for the backend and npm start for the front) all are running on my localhost on different ports.
what i need to do is to move that MERN app to an ubuntu machine and make it accessible via LAN network of that ubuntu continuously.
i guess i need to use git to move the app from windows to ubuntu? (correct me if i'm wrong) but how to make it run correctly there? and should i install a specific server to run it all on the LAN?
Thank you for the help in advance !

Node.JS: Why is my connection to localhost:3000 refused?

I'm a student going into back-end development for the first time and are trying to learn Node.JS. I downloaded a pdf book about Node.JS from sitepoint called: "Jumpstart Node.JS". In following the instructions to set up the server on the command line, install the dependencies, and navigate to localhost:3000, i got nothing except the following message: "Connection refused: localhost:3000", Can somebody please tell me what might have went wrong and how to fix it?
Edit1:
The instructions i followed is about setting up a node.js server using the Node command line, thus no code, simply cmd commands, however, here is a quick summary of the process i followed:
Created an account on MongoLabs and then a database using the free pricing plan.
Installed express using the command: npm install -g express#.2.5.8.
Created an applications with default options using this command: express authentication.
modified the package.json file in system32
installed the dependencies by typing cd authentication, hitting enter, and then typing the command: npm install
Typed node app and hit enter.
According to the instructions i should have seen a message: "Welcome to express" but instead got the error message.
In following the instructions to set up the server on the command line, install the dependencies, and navigate to localhost:3000
It seems that you didn't start the server.
Somewhere between installing the dependencies and navigating to the URL you need to actually start the server if you want it to serve the request.
Check that there is no copy of the server running in the background, or that another app is using the port currently.
(Your firewall show allow you to see which app has been allocated to that port)
Because nodejs requires it to be the only app on that port running on your computer.
Also try a different port maybe?

React native running on the device error

my react native app wont run when the device is connected on my laptop.. but the app will run successfully on genymotion. I dont know what the problem is. Can anyone suggest me some solutions to this problem. Thank you
This is problem i get on my device, but no problem when running on genymotion
check this out, probably you not set up your dev server
https://facebook.github.io/react-native/docs/running-on-device-android.html#configure-your-app-to-connect-to-the-local-dev-server-via-wi-fi
Make sure your laptop and your phone are on the same Wi-Fi network.
Open your React Native app on your device. You can do this the same way you'd open any other app.
You'll see a red screen with an error. This is OK. The following steps will fix that.
Open the Developer menu by shaking the device or running adb shell input keyevent 82 from the command line.
Go to Dev Settings.
Go to Debug server host for device.
Type in your machine's IP address and the port of the local dev server (e.g. 10.0.1.1:8081). On Mac, you can find the IP address in System Preferences / Network. On Windows, open the command prompt and type ipconfig to find your machine's IP address (more info).
Go back to the Developer menu and select Reload JS.
what your android version device ?
the first think should you do after your plugg in your device via usb, check that your device is properly connecting to ADB by running adb devices.
Open your cmd find your adb directory path example : C:\Users\your_name\AppData\Local\Android\sdk\platform-tools
Run $ adb devices and see list devices attached. U must have one devices only one device connected at a time.
After check devices are connected and then run your app $ react-native run-android.
If your android version 5.0 lollipop running the following in your cmd $ adb reverse tcp:8081 tcp:8081 and you can reload your aplication, but if still error you can run via wi-fi, you can use this tutorial if you run via wi-fi, but you'll first need to install the app on your device using a USB cable.

Red Screen React Native Reference Error : Can't find variable : _fbBatchedBridge

I followed the steps mentioned in following documents and everything runs perfectly.
https://facebook.github.io/react-native/docs/getting-started.html
https://facebook.github.io/react-native/docs/android-setup.html
https://facebook.github.io/react-native/docs/running-on-device-android.html
Now am trying to run the android app on my device but I get below error.
I tried following to resolve the issue:
react-native start > /dev/null 2>&1 &
adb reverse tcp:8081 tcp:8081
If I try to run without a server, bundle the jsfile into the apk by running:
curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
I get
I followed all the steps outlined in this question react native android failed to load JS bundle but still I am not able to resolve the issue.
I am using my smartphone's data plan on my OSX machine via hotspot. I entered my machine's IP address inet 192.168.43.14 along with port 8081 in the react-native developer setting.
Any idea what am missing here?
Device details:
OSX El Capitan 10.11.1
Nexus 5(Rooted) 6.0.1
Node - v4.2.1

Categories

Resources