The best way to run npm install for nested folders?
Per @Scott's answer, the install|postinstall script is the simplest way as long as sub-directory names are known. This is how I run it for multiple sub dirs. For example, pretend we have api/
, web/
and shared/
sub-projects in a monorepo root:
// In monorepo root package.json
{
...
"scripts": {
"postinstall": "(cd api && npm install); (cd web && npm install); (cd shared && npm install)"
},
}
On Windows, replace the ;
between the parentesis with &&
.
// In monorepo root package.json
{
...
"scripts": {
"postinstall": "(cd api && npm install) && (cd web && npm install) && (cd shared && npm install)"
},
}
I prefer using post-install, if you know the names of the nested subdir. In package.json
:
"scripts": {
"postinstall": "cd nested_dir && npm install",
...
}