While trying to do the MERN tutorial(Travers Media), i've also been asking a few questions to my friends who do code. And it irritates my friend that i don't separate client folder and server folder. but since my plan is to run both backend and frontend at the same time with concurrently, it hasn't actually been working.

"scripts": {
    "start": "node server.js",
    "server": "nodemon server.js",
    "client": "npm start  --suffix --prefix client",
    "dev": "concurrently \"npm run server\" && \"npm run client\""

  },

enter image description here

1

There are 1 answers

0
gman On

concurrently doesn't seem to use && and no idea what --suffix --prefix client is supposed to do. Did you mean to start the server twice?

In any case getting rid of the && and adding an extra -- to the "client" script works for me

package.json

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node server.js",
    "server": "nodemon server.js",
    "client": "npm start --  --suffix --prefix client",
    "dev": "concurrently \"npm run server\" \"npm run client\""
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "concurrently": "^5.3.0",
    "nodemon": "^2.0.4"
  }
}

server.js

const msg = process.argv[process.argv.length - 1] === 'client' ? 'client' : 'server';
console.log(process.argv.join(' '));
setInterval(() => {
  console.log(msg);
}, 2000);