To install React JS in Visual Studio Code using npm, follow these steps:
- Open Visual Studio Code: Launch Visual Studio Code on your computer.
- Create a New Folder: Create a new folder for your React project.
- Open the Folder in VS Code: Open the newly created folder in Visual Studio Code.
- Open the Terminal: Open the integrated terminal in VS Code by going to View -> Terminal.
- Initialize npm: Run the command
npm init -y
in the terminal. This initializes an npm project in the folder and creates apackage.json
file. - Install Create React App: Run the command
npm install -g create-react-app
to install the Create React App globally. - Create React Project: Use the command
create-react-app my-react-app
to create a new React project named "my-react-app". Replace "my-react-app" with your desired project name. - Navigate to the Project Folder: Use the command
cd my-react-app
to navigate to the newly created project folder. - Start the Development Server: Run the command
npm start
to start the development server. This will open the React application in your default browser.
Example:
# Open VS Code
# Create a new folder named "my-react-app"
# Open the "my-react-app" folder in VS Code
# Open the terminal in VS Code
# Initialize npm
npm init -y
# Install Create React App globally
npm install -g create-react-app
# Create a new React project
create-react-app my-react-app
# Navigate to the project folder
cd my-react-app
# Start the development server
npm start
Note: If you encounter any errors, make sure you have Node.js and npm installed on your system. You can download them from the official Node.js website.