Antonis Christofides
Antonis Christofides

Reputation: 6939

What is the react-native webserver and why is it needed?

If I type the following:

react-native start --help

this is what I get:

react-native start [options]
starts the webserver

Eh, what webserver? Why do I need one? How is it being used when I type react-native run-android?

Upvotes: 2

Views: 1944

Answers (1)

bennygenel
bennygenel

Reputation: 24660

react-native start command like you can see starts a web server. Th purpose of this webserver is to bundle your javascript code and serve it while you are in development mode. This server will re-bundle and serve the new bundled code when you reloaded your app.

While in development version of your app the bundled version of your javascript code will be server from this webserver. If you create a release version of your app, build process of react-native will start the webserver and then it will include the this bundled version in your app. This way it can be loaded from local file system.

This article about react-native also explains it a little.

React Native packages our React Native JavaScript files and serves them on localhost:8081. That’s right, it’s just like any other web server if you open your browser at http://localhost:8081/index.ios.bundle?platform=ios&dev=true. Open it in your browser now. Search for “hello”. You will see the React Native code bundled up together in one big file. This should sound familiar to most web developers. ;-)

Upvotes: 4

Related Questions