Last modified: Jul 20, 2025 By Alexander Williams
How to Install React in Node.js
React is a popular JavaScript library for building user interfaces. Installing it in Node.js is simple. This guide will walk you through the process.
Prerequisites
Before installing React, ensure you have Node.js and npm installed. You can check by running:
node -v
npm -v
If not installed, download Node.js from the official website. It includes npm.
Create a New Project
First, create a new directory for your project. Navigate to it in your terminal.
mkdir my-react-app
cd my-react-app
Initialize Node.js Project
Run npm init
to create a package.json file. Follow the prompts or use npm init -y
for default settings.
npm init -y
Install React
Use npm to install React and ReactDOM. Run the following command:
npm install react react-dom
This installs React and its DOM-specific methods. Both are essential for React development.
Verify Installation
Check package.json to ensure React is listed under dependencies. It should look like this:
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
Set Up a Basic React App
Create an index.html file and a src folder. Add an App.js file inside src.
<!DOCTYPE html>
<html lang="en">
<head>
<title>React App</title>
</head>
<body>
<div id="root"></div>
<script src="src/App.js"></script>
</body>
</html>
In App.js, add a simple React component:
import React from 'react';
import ReactDOM from 'react-dom';
const App = () => {
return <h1>Hello, React!</h1>;
};
ReactDOM.render(<App />, document.getElementById('root'));
Use Create React App (Optional)
For a quicker setup, use Create React App. It configures everything automatically.
npx create-react-app my-app
cd my-app
npm start
This sets up a full React project with a development server.
Additional Tools
Enhance your React project with tools like ESLint or Dotenv. They improve code quality and manage environment variables.
Conclusion
Installing React in Node.js is straightforward. Use npm to add React and ReactDOM. For a faster start, try Create React App. Happy coding!