How To Connect Node with React?
Last Updated :
09 Apr, 2025
To connect Node with React, we use React for the frontend (what users see) and Node.js for the backend (where the server logic lives). The frontend sends requests to the backend, and the backend responds with data or actions.
There are many ways to connect React with Node.js, like using Axios or Fetch or setting up a proxy. In this article, we’ll keep things simple and use the proxy method to make them work together smoothly.
Steps To Setup The Backend
Follow these basic steps to create the backend of your Node.js application:
Step 1: Create a backend directory
mkdir demoapp
cd demoapp
Step 2: Initialize the Project
npm init -y
Ensure that the entry point is set to either app.js or index.js
Step 3: Install the required libraries
npm i express nodemon
The updated dependencies in package.json file will look like:
"dependencies": {
"express": "^5.1.0",
"nodemon": "^3.1.9",
}
Steps To Setup the Frontend
Follow these steps to set up the React frontend:
Step 1: Create react app using this command
npx create-react-app demo
Step 2: Move to the project directory
cd demo
The updated dependencies in package.json file will look like:
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
}
Project Structure

Folder Structure
Example: This example shows basic program for backend server.
JavaScript
// Filename - demoapp/app.js
const express = require("express");
const app = express();
app.post("/post", (req, res) => {
console.log("Connected to React");
res.redirect("/");
});
app.get('/',(req,res)=>{
res.send(`<h1>Hello World</h1>`)
})
const PORT = process.env.PORT || 8080;
app.listen(PORT,
console.log(`Server started on port ${PORT}`)
);
Run the application using the following command:
npm run dev
Output: Now go to http://localhost:8080/ in your browser, you will see the following output.

Connect React to Node with Proxy
To connect React with Node using a proxy, add this line in your React app’s package.json file right after the “name” and “version” fields at the top:
"proxy": "http://localhost:8080"
This tells React to automatically forward any unknown requests (like /post) to your Node.js backend running on port 8080 during development.
Example: This example includes the prontend implementation of proxy and react web page with button to connect to the backend.
JavaScript
// Filename - App.js
import logo from "./logo.svg";
import "./App.css";
function App() {
return (
<div className="App">
<header className="App-header">
<img
src={logo}
className="App-logo"
alt="logo" />
<p>A simple React app.....</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer">
Learn React
</a>
<form
action="../../post"
method="post"
className="form">
<button type="submit">
Connected?
</button>
</form>
</header>
</div>
);
}
export default App;
Steps to run React app: Run this command in terminal
npm start
Output: This output will be visible on http://localhost:3000/ on browser window.
Other Methods to Connect Node with React
Apart from the proxy method, there are several ways to connect a React frontend with a Node.js backend. These methods help manage communication and data flow between the client and server more efficiently.
- Axios or Fetch API: Used to send HTTP requests from React to Node endpoints.
- CORS Setup: Directly allow cross-origin requests by configuring CORS on the Node server.
- GraphQL: An alternative to REST APIs that enables flexible data querying between frontend and backend.
Similar Reads
How To Connect MongoDB with ReactJS?
MongoDB is a popular NoSQL database known for its scalability, flexibility, and high performance. When building modern web applications with ReactJS, itâs common to connect your frontend with a backend server that interacts with a database like MongoDB. PrerequisiteReact JSNode JSMongo DBApproach to
5 min read
How to connect ReactJS with MetaMask ?
To Connect React JS with MetaMask is important while making Web 3 applications, It will be done with Meta mask wallet which is the most used browser tool for sending and receiving signed transactions . MetaMask is a crypto wallet and a gateway to blockchain DAPP. It is used to connect our app to web
3 min read
How to Connect Django with Reactjs ?
Connecting Django with React is a common approach for building full-stack applications. Django is used to manage the backend, database, APIs and React handles the User Interface on frontend. Prerequisites:A development machine with any OS (Linux/Windows/Mac).Python 3 installed.Node.js installed (ver
9 min read
How to connect ReactJS with flask API ?
Connecting React with Flask API allows us to create a full-stack web application with React handling the user interface at frontend and Flask serving the data in backend. Here React makes the HTTP request to interact with the flask API to perform operations with the database. ApproachTo connect Reac
4 min read
How to connect mongodb Server with Node.js ?
mongodb.connect() method is the method of the MongoDB module of the Node.js which is used to connect the database with our Node.js Application. This is an asynchronous method of the MongoDB module. Syntax: mongodb.connect(path,callbackfunction)Parameters: This method accept two parameters as mention
2 min read
How to write comments in ReactJS ?
When working with ReactJS or any other programming language, making the code easy to understand is essential. One of the best ways to do this is by using comments. Comments are simple notes within the code that help to explain what is happening or why something was done in a specific way. To write c
3 min read
How to write ReactJS Code in Codepen.IO ?
Now everything is online, some people use VScode to write react.js code and face most of the difficulty. The VScode requires setting for writing React.js code and Many beginners faced difficulty to use VScode so, for them, it is good and easy to use codepen. The codepen provide you with an online pl
2 min read
How To Create a Website in ReactJS?
ReactJS is one of the most popular JavaScript libraries for building user interfaces. It allows you to create dynamic, reusable UI components and efficiently manage state and events. In this article, we'll walk through the steps to create a basic website using ReactJS. PrerequisitesNPM & Node.js
5 min read
How to Use Bootstrap with React?
Bootstrap is one of the most popular front-end frameworks, widely used to create visually appealing, responsive, and mobile-first websites quickly. It provides pre-designed UI components, grid systems, and various CSS classes that help you build mobile-first, responsive web applications quickly and
9 min read
How to create components in ReactJS ?
Components in React JS is are the core of building React applications. Components are the building blocks that contains UI elements and logic, making the development process easier and reusable. In this article we will see how we can create components in React JS. Table of Content React Functional C
3 min read