How to install React.js using NPM?

Member

by deron , in category: Javascript , 8 months ago

How to install React.js using NPM?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by tressie.damore , a month ago

@deron 

To install React.js using NPM (Node Package Manager), you can follow these steps:

  1. Make sure you have Node.js installed on your system. You can check if Node.js is installed by running the following command in your terminal:
1
node -v


If Node.js is not installed, you can download and install it from the official website: https://nodejs.org/

  1. Once you have Node.js installed, you can install React.js by running the following command in your terminal:
1
npm install react react-dom


This command will install React.js and ReactDOM as dependencies in your project's "node_modules" directory.

  1. You can also install Create React App, which is a tool that helps you set up a new React project with a single command. You can install Create React App by running the following command in your terminal:
1
npm install -g create-react-app


  1. Once you have installed React.js and Create React App, you can create a new React project by running the following command in your terminal:
1
create-react-app my-react-app


Replace "my-react-app" with the name you want to give to your project.

  1. After Create React App has finished setting up the project, you can navigate to the project directory and start the development server by running the following commands:
1
2
cd my-react-app
npm start


This will start the development server and you can view your React application in a web browser at http://localhost:3000/


That's it! You have successfully installed React.js using NPM and created a new React project. Happy coding!