DEV Community

Cover image for How to run Front End and Backend together in React.js and Express.js with 'concurrently' package
Era Codex
Era Codex

Posted on

21 2 1 1 1

How to run Front End and Backend together in React.js and Express.js with 'concurrently' package

Run Front End and Backend Concurrently

If you are looking for a way to run Front End and Backend together with React.js and Express.js, you may simply follow these steps:

Step 1:

Install 'concurrently'

npm install concurrently --save
Enter fullscreen mode Exit fullscreen mode

Step 2:

Find the script start in package.json file

By default the script looks like this

"start": "react-scripts start",
Enter fullscreen mode Exit fullscreen mode

First add concurrently to that script like this with backslashes and quote marks

"start": "concurrently \"react-scripts start\" ",
Enter fullscreen mode Exit fullscreen mode

Look, now if you run npm start it will call concurrently first which will run the 'react-scripts start' command and if you want to add more command you have to add the scripts (commands) like the above format with backslashes and quote marks for each scripts, let's do it in the next step

Step 3:

Add more scripts to concurrently. Now, if we have a backend folder with backend codes, first we need to move onto the backend directory (cd backend) (use necessary command to move onto your relevant folder), then at the same time we will call nodemon which will run our server.js file (nodemon server), let's do it

"start": "concurrently \"react-scripts start\" \"cd backend && nodemon server\"",
Enter fullscreen mode Exit fullscreen mode

That's it. Now you can use a single command and run front end and backend concurrently from your main/root project folder.

npm start
Enter fullscreen mode Exit fullscreen mode

Heroku

Amplify your impact where it matters most — building exceptional apps.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (5)

Collapse
 
jstewart8053 profile image
jstewart8053

Sorry if this is a bad question, but what if you are running in production? Do you do npm build on the front end and backend, if they are in two seperate repos? I'm working on a project where the front end and back end have there own repo but are under the same folder. I'm unsure of where to do npm run build at.

Collapse
 
vineyrawat profile image
Viney Rawat

This is for development only don't use it in production

Collapse
 
nuno111 profile image
Nuno111

Thanks for this Mamun, works great for my dev environment!

I'm wondering throught, why aren't we installing this package as a dev dependency only?

Since we are not using this for production and mainly to run the application in dev environment only.

Cheers!

Collapse
 
mfurkankaya profile image
Furkan KAYA

Will this "npm start" work on a server? I mean, is it only for developing or will this let the project's front end and back end run on the same host?

Collapse
 
eracodex profile image
Era Codex

I've implemented this on the development mode (it can be run on the same host using different ports), and on an active server after the successful deployment of the production/build codes it should run automatically.

Thank you for your comment.

Playwright CLI Flags Tutorial

5 Playwright CLI Flags That Will Transform Your Testing Workflow

  • --last-failed: Zero in on just the tests that failed in your previous run
  • --only-changed: Test only the spec files you've modified in git
  • --repeat-each: Run tests multiple times to catch flaky behavior before it reaches production
  • --forbid-only: Prevent accidental test.only commits from breaking your CI pipeline
  • --ui --headed --workers 1: Debug visually with browser windows and sequential test execution

Learn how these powerful command-line options can save you time, strengthen your test suite, and streamline your Playwright testing experience. Practical examples included!

Watch Video 📹️

👋 Kindness is contagious

DEV is better (more customized, reading settings like dark mode etc) when you're signed in!

Okay