I want to work with reactnative and node.js both on visual studio code in the same project. But I’m having trouble connecting between them.
A lot of resources on the internet weren’t practical or useful.
I want to work with reactnative and node.js both on visual studio code in the same project. But I’m having trouble connecting between them.
A lot of resources on the internet weren’t practical or useful.
2
Answers
It should be fairly straight forward but here’s a simple guide on how to with both easily:
Create a folder for the entire project
Create two subfolders, one for your react native project (I usually name it app) and one for your server (node.js).
Make sure to install nodemon in your server folder, and add this part in your package.json
Notice that I added the part called "devstart". Then you simply run "npm run devstart". Now your Node.js project is running and is reloading whenever you make changes.
You can now make API calls to your node.js backend, as long as you use the correct port number etc. I usually use Axios package for both ReactJS and React Native, I strongly recommend it!
Hope this helps!
First, you’ll need to understand the difference between code running on the server (nodejs) and code running on the client (reactnative).
The Nodejs code you’re writing is propably for a webserver. This webserver is running on a server (not on the device of the reactnative client). To access this webserver, you can make http calls (e.g. webserver.com/api/hello could return the JSON
{ 'value': 'hello' }
.Your reactnative application runs on a specific device. If your server is running it’s possible to make http calls to the server.