Can npm be used to run scripts in multiple subfolders?

I have a folder (project) with three subfolders (client, server, assets). Each subfolder has a different team to start and work on the project that I need to run 3 applications. This is the layout of the folder and the commands that I use to run each subproject:

  • Project
    • customer (ionic service)
    • server (node ​​index)
    • assets (http-server -p 8082)

Currently, I go to each of the three folders and run each of the applications. To make the process more standard, each subproject has package.json with the start of the script, so I just cd subfolder && npm start .

My question is: can I use npm in the parent folder (i.e. write package.json there) so that I can just run the following command and have the same (or similar) effect?

project> npm start

I tried using the parallelshell package but it did not work (possibly due to cd :

 "scripts": { "start": "parallelshell 'cd app && ionic serve' 'cd api && npm start' 'cd assets && npm start'", } 
+16
npm
source share
3 answers

You can use "at the same time" to achieve this goal. Therefore, you should create package.json that will look something like this:

 ... "scripts": { "client": "cd client && npm start", "server": "cd server && npm start", "assets": "cd assets && ionic serve", "start": "concurrently \"npm run client\" \"npm run server\" \"npm run assets\" ", }, ... "devDependencies": { "concurrently": "^1.0.0" } ... 

Note: this will start all three processes at once, which means that you will get mixed output of all three (as mentioned by topheman)

+47
source share

The problem is that all three scripts are starting the server as a script, which means that they do not look like a build task (for example) that works for 10 seconds and stops the process.

For each of them, you run them , and the process continues indefinitely .

You can start all of them using a daemon with something like forever , but in your case you are in dev mode (so you want all the logs > and you don’t need errors from the nodejs mixed server with ion ...).

If you don't mind mixing logs: https://www.npmjs.com/package/forever (I assume this is almost the same as parallelshell ...)

+4
source share

it's too late to answer, but you have a build mode --prefix Example:

 -package.json -/dist/ssr/package.json 
 # package.json in root npm run start --prefix dist/ssr 
+1
source share

All Articles