What is the role of Node.js in React-Native?

I’m trying to understand the development process of React-Native, so I’ve found information about Metro, And then I’ve read/watch this Metro video):

Metro is the development platform for React Native and it does that by
exposing an HTTP server so clients, in this case, emulators can
communicate with it and it also exposes a Websocket server so it can
push updates into the clients.

The docs talk about the “React Native Packager” (now called Metro, according to the video) which runs on port 8081, so that is the HTTP server that starts when we type react-native run-android for example?

Regarding the Websocket I still need to read more.

The documentation says we’re running our JavaScript code in two environments, depending if we’re in debug mode or not, which I understood. But this article confused me a little bit, says:

No. 4 You Code Does Not Run on Node.JS: The JavaScript runtime you’ve got is ether JavaScriptCore (non-debug) or V8 (debug). Even
though you can use NPM and a node server is running on the background,
your code does not actually run on Node.JS. So you won’t be able to
use of the Node.JS packages. A typical example is jsonwebtoken, which
uses NodeJS’s crypto module.

And, then I’ve read things like:

React Native uses Node.js, a JavaScript runtime, to build your
JavaScript code.

Node.js is a server-side JavaScript runtime environment. React
Native ships with some tools that are written for Node.js.

Node.js is an open source platform built on Chrome’s JavaScript
runtime; it offers a way to easily build fast, scalable
programs. Node.js allows you to run JavaScript in Terminal, and helps
create modules.

In this article, it says:

Download node.js from nodejs.org. This JavaScript runtime gives you
access to npm, which is a convenient tool created by the node.js
project that you can use to manage open source packages. Make sure
that you download the latest LTS (Long Term Support) version of
node.js. Also included with this download is a development server
called the Metro bundler, which provides live updates when debugging.


  • The role of Node.js in RN is to only access npm and manage the packages? and is Metro is includes in Node.js? Am I missing/confusing something? Thank you.
Read More:   how to require from URL in Node.js

There are four types of JavaScript you’ll write in todays environments:

1) Clientside browser JavaScript:

That’s what gets sent to webbrowsers when they visit your webpage, it then gets executed in the browser at the clientside. As you want the JS to load fast and run on all kinds of browsers, you usually use transpilers to turn the modern ESnext you write into a minified version with better support.

2) Clientside native JavaScript:

Most devices do have a native JS runtime, therefore you can ship JS files with your Android / iOS / Desktop application and then start them there. These engines also support adding hooks from JavaScript into your native code, that’s how React Native does provide it’s APIs.

3) Serverside NodeJS JavaScript:

NodeJS is a runtime you’ll use to run servers.

4) Buildscripts running on NodeJS:

You can use JavaScript to generate JavaScript files. That’s how you bundle the files for (1) and (2) (maybe also (3)).

Now metro is a serverside buildscript (on NodeJS) that you can use to either a) start a server that serves your JS as a webpage (1 & 3), or b) that bundles your JS in a native App that you can install on your device (2).

The role of Node.js in RN is to only access npm and manage the packages?

No. metro is itself a package that you then run on NodeJS.

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Similar Posts