Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • React Tutorial
  • React Exercise
  • React Basic Concepts
  • React Components
  • React Props
  • React Hooks
  • React Router
  • React Advanced
  • React Examples
  • React Interview Questions
  • React Projects
  • Next.js Tutorial
  • React Bootstrap
  • React Material UI
  • React Ant Design
  • React Desktop
  • React Rebass
  • React Blueprint
  • JavaScript
  • Web Technology
Open In App
Next Article:
How To Connect MongoDB with ReactJS?
Next article icon

How To Connect Node with React?

Last Updated : 09 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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

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.

  1. Axios or Fetch API: Used to send HTTP requests from React to Node endpoints.
  2. CORS Setup: Directly allow cross-origin requests by configuring CORS on the Node server.
  3. GraphQL: An alternative to REST APIs that enables flexible data querying between frontend and backend.


Next Article
How To Connect MongoDB with ReactJS?
author
_sh_pallavi
Improve
Article Tags :
  • JavaScript
  • Node.js
  • ReactJS
  • Web Technologies
  • CSS-Functions
  • Java-HijrahDate
  • Java-SecureRandom
  • NodeJS-Questions
  • QA - Placement Quizzes-Data Interpretation
  • React-Questions
  • SQL-PL/SQL
  • TCS-coding-questions
  • Technical Scripter 2020

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 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 Modal Component In ReactJS?
    Modals are a popular UI component used to display content in a pop-up window like alerts, forms, or additional information. In ReactJS, there are multiple ways to implement a modal. In this article, we will discuss two common approaches: using reusable functional components and using the Material-UI
    4 min read
  • How to use NoSsr Component in ReactJS?
    NoSsr purposely removes components from the subject of Server Side Rendering (SSR). Material UI for React has this component available for us, and it is very easy to integrate. We can use the NoSsr Component in ReactJS using the following approach. Prerequisites:NodeJS or NPMReactJSMaterial UISteps
    2 min read
  • How to send Basic Auth with Axios in React & Node ?
    Basic Auth is a simple authentication scheme. It involves sending a username and password with each request to the server through HTTP. Axios is a popular HTTP client for making requests in JavaScript. In this article, we will create a React App to demonstrate sending basic Auth with Axios and discu
    5 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
  • How to Setup a Modern React Chatbot
    Integrating a chatbot into your React application can enhance user experience and provide valuable assistance to your users. With the availability of various libraries and tools, setting up a modern chatbot in a React project has become more straightforward. In this article, we'll explore how to set
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences