Table of Contents

Step 1: Install Node.js and npm
Before setting up your React project, ensure you have Node.js and its package manager, npm, installed on your system. Node.js is essential for running JavaScript code outside the browser, and npm manages your project’s dependencies.
- Visit the official Node.js website.
- Download and install the latest LTS version.
- Verify the installation by running the following commands in your terminal:
node -v
npm -v
- Both commands should return a version number, confirming successful installation.
Step 2: Install Create React App
Create React App is a command-line tool that simplifies the React setup process, providing everything you need to start coding immediately.
Open your terminal or command prompt and run:
npx create-react-app my-first-react-app
Replace “my-first-react-app” with your project name.
The tool will automatically set up the initial project structure and install all the necessary dependencies, such as Webpack, Babel, and other key React libraries.
Step 3: Navigate to Your Project Directory
cd my-first-react-app
Step 4: Start the Development Server
npm start
Step 5: Explore the Project Structure
The Create React App structure is simple and well-organized:
- node_modules/: Contains all the installed dependencies.
- public/: Holds static files like
index.html
, which serves as the entry point of your React app. - src/: The source code folder where you will spend most of your time. It contains files like
App.js
where you will build your components.
Step 6: Customize Your App
Now that the setup is complete, you can start customizing your app by editing the src/App.js
file. Here’s how you can replace the default text:
- Open
src/App.js
in your preferred code editor. - Replace the default content inside the
<div>
element with:
function App() {
return (
Hello, React World!
);
}
- Save the file, and your browser will automatically refresh, displaying the updated text.
Step 7: Install Additional Dependencies
npm install
npm install react-router-dom
Step 8: Run Build for Production
npm run build
Conclusion
Setting up a React project using Create React App is straightforward, even for beginners. With just a few commands, you can have a fully functional React environment ready to develop powerful, scalable web applications. As you grow more comfortable with React, you can explore additional tools and libraries to enhance your app further.
Stay tuned for more React tutorials and resources to continue your development journey!