Set Up Your First Website Using React.js
Thilinika Evanthi Wadanambi
Undergraduate at University of Moratuwa | Faculty of Information Technology | B.Sc. (Hons) IT | Writer
In the past few days, I have tried to build different websites using React.js. When it comes to making a website, the first step is to Set up the environment and tools. In this article, I will tell you how to set up your first website using React.
Download the Node.js
With Node.js, you can easily code. You need npm to run and manage packages, which generally requires Node.js. You can download this from the official Node.js website.
Get the VS code
Personally, I like to use VS code. You can use any code editor as you want. To download the VS code, go to their original website.
Install the npm packages
After that, open the VS code and the terminal. You can see it on the tools bar. In there, type
npm install
This command will install all the necessary packages for your React application, including React, ReactDOM, and other dependencies.
Create a New React Application
To create a new React application, use the Create React App tool. This tool sets up everything you need for a React project. Run the following command in the terminal:
npx create-react-app my-first-react-app
Replace my-first-react-app with your desired project name. This command will create a new directory with the same name and set up a React application in it.
领英推荐
Navigate to Your Project Directory
Once the project setup is complete, navigate into your project directory by running:
cd my-first-react-app
Start the Development Server
Now that you're inside your project directory, you can start the development server to see your React app in action. In the terminal, run:
npm start
This command starts the React development server, and you should see output in the terminal indicating that the server is running. By default, your app will be accessible https://localhost:3000 in your web browser.
Modify Your First Component
Let's modify the default App.js component to display a custom message. Open src/App.js and replace its content as you want.
Save the file, and you should see the changes reflected in your browser.
Install Additional Packages
As you build your React application, you may need to install additional npm packages. For example, to install axios for making HTTP requests, run:
npm install axios
With this foundation, you can dive deeper into React and create amazing web applications.