Run client and server together in Node JS using concurrently

To run the client and server together in Node.js using concurrently, you need to ensure that both the client and server processes are started concurrently. You can do this by creating a script in your root package.json that utilizes concurrently to start both processes. Here’s how you can modify your package.json

{
 "name": "nasa-project",
 "version": "1.0.0",
 "description": "",
 "main": "index.js",
 "scripts": {
  "client": "npm run dev --prefix client",
  "server": "npm run dev --prefix server",   
  "start": "concurrently "npm run client" "npm run server"",
  "test": "echo "Error: no test specified" && exit 1"
 },
 "keywords": [],
 "author": "",
 "license": "ISC",
 "dependencies": {
  "concurrently": "^8.2.2"
 }
}
  • The start script uses concurrently to run both the client and server scripts simultaneously.
  • When you run npm start, it will start both the client and server concurrently.

Make sure you have concurrently installed in your project. If not, you can install it using:

npm install concurrently --save-dev

Once installed, you can use npm start to run both the client and server together.

Leave a comment

Your email address will not be published. Required fields are marked *