Mobile Development 22 min read

Understanding the React Native CLI: How It Creates and Configures a New RN Project

This article explains how the react-native-cli tool automates the creation of a React Native project by installing required software, generating the project structure from templates, installing node and iOS dependencies, and detailing the underlying code flow from the CLI entry point to the init and generateProject functions.

JD Retail Technology
JD Retail Technology
JD Retail Technology
Understanding the React Native CLI: How It Creates and Configures a New RN Project

The react-native-cli is a scaffolding tool bundled with React Native that lets developers quickly generate a complete RN project from the command line.

Before using it, you need to install Homebrew, Node.js, optionally Yarn, Xcode for iOS, and an editor such as WebStorm.

Install the CLI globally with npm install -g react-native-cli , then create a new app using react-native init MyRNProject .

The CLI consists of two parts: the react-native-cli package itself and the @react-native-community/cli located inside the React Native engine.

Running which react-native shows the binary points to a wrapper script that loads index.js of the CLI package.

In WebStorm you can debug the CLI by setting the Node interpreter, the working directory to your workspace, and the application parameters to the init command; breakpoints in index.js let you step through the execution.

The entry file imports utilities ( fs , path , child_process , etc.), parses command‑line arguments with minimist , determines the CLI module path, and dispatches commands. When the init command is detected, it calls init(name, options) .

The init function validates the project name, checks for existing directories, and finally invokes createProject(name, options) , which writes a package.json , creates the project folder, and calls run(root, projectName, options) .

The run function installs the React Native engine via execSync('npm install --save --save-exact react-native') , checks the Node version, loads the local CLI module, and calls cli.init(root, projectName) .

To debug the local CLI, an index.js file can be added with:

#!/usr/bin/env node
'use strict';
var cli = require('./cli');
cli.init('/Users/dingxin/Documents/workspace/Node/TestRNProject', 'TestRNProject');

The core of project creation lives in generateProject inside @react-native-community/cli . It copies a template project, installs the React version, adds dev dependencies (Babel, ESLint, Jest, etc.), and on macOS installs CocoaPods for iOS.

Template copying is performed by copyProjectTemplateAndReplace , which recursively walks the template directory and calls copyAndReplace for each file. copyAndReplace creates directories, copies binary files unchanged, and for text files reads the content, applies replacements (e.g., replacing HelloWorld with the new project name), and writes the modified file.

In summary, the CLI first installs itself, then the react-native init command triggers project scaffolding: template copying, node module installation, dev‑dependency installation, and optional iOS pod setup, resulting in a ready‑to‑run React Native application.

DebuggingMobile DevelopmentcliNode.jsReact NativeProject Initialization
JD Retail Technology
Written by

JD Retail Technology

Official platform of JD Retail Technology, delivering insightful R&D news and a deep look into the lives and work of technologists.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.