How to set up reactjs project
Install Node.js and npm Before setting up your React project, make sure you have Node.js and npm (Node Package Manager) installed on your computer. Node.js official website (https: https://nodejs.org).
Step 2: Create a new react project
After installing Node.js and npm, you can create a new React project using Create React App (CRA). CRA is a command line tool that sets up a new React project with basic project structure and configuration.
1. Open a terminal or command prompt.
2. Navigate to the directory where you will create your React project.
3. Create a new React project named "my-app" by running the following command:
npx create-react-app my-app
(Note: Replace "my-app" with any project name. ) CRA will generate the necessary files and install the required dependencies for your React project.
Step 3: Understand project structure
Once the project is created, use Terminal or Command Prompt to navigate to the project directory.
cd my-app
The project directory has the following files and folders:
src folder: React application's source code is located in the folder src.
public folder: The "index.html" HTML template file is located in this folder and is used to render React apps. React is used to create SPA apps because of this file.
package.json file: This file contains your project configuration and dependency list.
Step 4: Start the React development server
To see your React application in action, start the React development server.
1. Make sure you are in the project directory in a terminal or command prompt.
2. Start the development server by running the following command:
npm start
Your code will be compiled by the React developer server, the required files will be packaged, and the local developer server will be launched at http://localhost:3000.
Step 5:View the React application you are using in browser
Open a web browser, then go to http://localhost:3000, to view your React application.
You should see the default React logo and some sample content.
Congratulations! You have successfully set up a React project. You can now start modifying the code in the src folder to build your React application. Any changes you make will automatically trigger a live reload in the browser, allowing you to see the updates in real-time.
Remember to refer to the Create React App documentation (https://create-react-app.dev) for more details on customizing your project configuration and additional development tasks.