How to Add Express to React App using Gulp ?
Last Updated :
24 Apr, 2025
When building a web application with ReactJS, you may need to include a backend server for handling server-side logic and API requests. Express is a popular choice for creating backend servers in Node.js. In this tutorial, we'll explore how to integrate Express with a React app using Gulp as the build tool. Gulp will allow us to run both the React development server and the Express server concurrently.
Prerequisites:
Gulp
Gulp is a task runner and build system for JavaScript projects. It helps automate repetitive tasks such as file minification, compilation, testing, and more. It uses a simple and intuitive syntax, allowing developers to define tasks and dependencies easily. Gulp simplifies the development process by automating common workflows, making it a popular tool among web developers.
Steps to Configure Express to a React App using Gulp
Step 1: Initialize a new React project using Create React App by running the following command in your terminal:
npx create-react-app gfg
Step 2: Move to the project directory:
cd gfg
Step 3: Install Express and Gulp by running the following command in your terminal:
npm install express gulp
Project Structure:

The updated dependencies after installing required modules
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"express": "^4.18.2",
"gulp": "^4.0.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
}
Example: This example implements backend using gulp and express.
JavaScript
// Filename - gulpfile.js
const gulp = require("gulp");
const { spawn } = require("child_process");
// Define the task to start the Express server
gulp.task("start-server", () => {
const serverProcess = spawn("node", ["server.js"], {
stdio: "inherit",
});
serverProcess.on("close", (code) => {
if (code === 8) {
console.error(
"Error detected, waiting for changes..."
);
}
});
});
// Define the default task to start the React development server
gulp.task(
"default",
gulp.series("start-server", () => {
const reactProcess = spawn("npm", ["start"], {
stdio: "inherit",
});
reactProcess.on("close", (code) => {
if (code === 8) {
console.error(
"Error detected, waiting for changes..."
);
}
});
})
);
JavaScript
// Filename server.js
const express = require("express");
const app = express();
// Choose a port number
const port = 3001;
// Define your routes here
app.get("/api/data", (req, res) => {
// Handle the API request and send a response
res.json({ message: "Hello from the server!" });
});
// Start the server
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
Step to run server using gulp:
Step 1: Update the scripts: First update the "scripts" section to include a new script for running Gulp:
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"gulp": "gulp"
},
Step 2 Start the backend server: Use this command in the terminal inside project directory to start the server
npm run gulp
Start frontend server: Use this command in the terminal inside project directory to start the server
npm start
Output: The React app will be available at http://localhost:3000, and you can access the Express API endpoint at http://localhost:3001/api/data. When you visit the API endpoint in your browser, you should see the JSON response { "message": "Hello from the server!" }.
DemoBy following these steps, you've successfully added Express to your React app using Gulp. The React development server will run on the default port 3000, and the Express server will run on port 3001. You can modify these ports as needed in the server.js and gulpfile.js files.
Similar Reads
How to use the app object in Express ?
In Node and Express, the app object has an important role as it is used to define routes and middleware, and handling HTTP requests and responses. In this article, we'll explore the various aspects of the `app` object and how it can be effectively used in Express applications. PrerequisitesNode.js a
3 min read
How to Deploy React App using Azure Static Web Apps ?
Microsoft Azure is a public cloud computing platform. It provides a lot of cloud services to access, manage, and deploy applications. Where as Azure Static Web App is one of the services of Microsoft Azure. It automatically builds and deploys full-stack web apps from the code repository to azure. In
3 min read
How to create an App using Meteor ?
It is a full-stack javascript platform for developing web and mobile applications. The meteor uses a set of technologies to achieve our goal along with Node.js and JavaScript. It expects the least development efforts and provides the best performance. In this article, we are going to see how we can
4 min read
How To Make A GET Request using Postman and Express JS
Postman is an API(application programming interface) development tool that helps to build, test and modify APIs. In this tutorial, we will see how To Make A GET Request using Postman and Express JS PrerequisitesNode JSExpress JSPostmanTable of Content What is GET Request?Steps to make a GET Request
3 min read
How to Create a Simple Server Using ExpressJS?
The server plays an important role in the development of the web application. It helps in managing API requests and communication between the client and the backend. ExpressJS is the fast and famous framework of the Node.Js which is used for creating the server. In this article, we will create a sim
3 min read
How to deploy React app to Heroku?
React is a very popular and widely used library for building User Interfaces. So if you are thinking about deploying your React app to the cloud platform, there are various choices for doing that such as AWS EC2 or Heroku. But for testing your React app, Heroku will be the best option as it is free
3 min read
How to Integrate Stripe Payments in React App using Express ?
Many of the projects you develop might have a requirement to integrate the payment module in your application. Stripe serves as a payment processing platform designed to help applications securely accept and handle online payments. In this article, we will see how we can easily integrate payment sys
6 min read
How to Deploy React App on Netlify Using Github?
React App is a web or mobile application that is built using the React library of JavaScript. It helps users create interactive, single-page, and dynamic applications. These applications are built using HTML, CSS, and JavaScript. Deployment of a React app can be done via GitHub, Netlify, or any othe
6 min read
How to include css files using NodeJS, Express, and EJS?
CSS stands for âCascading Style Sheetâ. It is used to style web pages. CSS simplifies the process of making web pages presentable. It describes how web pages should look it prescribes colors, fonts, spacing, and much more. Including CSS files is important for styling web pages in web development wit
2 min read
How To Render Dynamic Lists Using EJS and Express ?
Rendering of dynamic lists in EJS and Express mainly allows us to dynamically generate the HTML content which is based on the data from the backend server. We can render dynamic lists using the '<% %>' tags. Steps to Render Dynamic ListsStep 1: Create a directory for the projectmkdir rootcd ro
2 min read