Home > database >  npm Install different folders with one script
npm Install different folders with one script

Time:10-12

I want to run one npm install on the project root to install both server and client packages.

My project structure is:

project
│   package.json
|   node express files...
└───client
    │   package.json
    |   react app files...

And also, create one script that runs npm run dev on the root folder and npm start on the client folder.

I tried to use concurrently, and it does work for running the apps, but for installing, I get a weird infinite loop that keeps installing in the root folder: terminal screenshot

And I guess if concurrently is not globally installed, it wouldn't work anyway for the first installation.

package.json scripts in the root folder:

  "scripts": {
    "test": "jest",
    "start": "node index.js",
    "build": "cd client && npm run build",
    "install-client": "cd client && npm install",
    "heroku-postbuild": "npm run install-client && npm run build",
    "dev-client": "cd client && npm start",
    "dev": "nodemon index.js",
    "install": "concurrently \"npm install\"  \"npm run install-client\"",
    "dev-both": "concurrently \"npm run dev\" \"npm run client-dev\""
  },

Any ideas how for a fix or an alternative way to do this?

Thanks in advance :)

CodePudding user response:

To avoid infinite loop, try this :

"both-install": "concurrently \"npm install\"  \"npm run install-client\"",
  • Related