0

I have a top level package.json file in my project and also one within a sub folder.

index.html
package.json
node_modules/
sub-folder/
sub-folder/package.json
sub-folder/node_modules/

I want to run a single command which will run npm install for both packages. In my top level package.json I have the following:

"scripts": {
  "start": "npm install sub-folder",

This does install the dependancies from the package.json in my sub folder, however it installs them in my top level node_modules folder, not the one nested in the sub folder.

Do I need to use custom JavaScript as in the answer below? It seems overkill to do so as im so close:

The best way to run npm install for nested folders?

Community
  • 1
  • 1
Evanss
  • 23,390
  • 94
  • 282
  • 505

1 Answers1

0

Ive done it with this:

"scripts": {
  "preinstall": "cd .sub-folder && npm install",

"preinstall" means that when someone runs npm install from the root then this line will execute first. "start" is more often used to start applications rather than install dependancies.

Evanss
  • 23,390
  • 94
  • 282
  • 505