Home > database >  Run npm command in exact folder with powershell
Run npm command in exact folder with powershell

Time:01-27

i want to run npm command in each folder

Get-ChildItem -Directory -Filter "desiredFolder" | ForEach-Object {&npm install}

Problem i am experiencing is that npm command runs from root folder where is script not from each folder from foreach. How can I fix it?

CodePudding user response:

Use Push-Location/Pop-Location to drop in and out of the directory while installing:

Get-ChildItem -Directory -Filter "desiredFolder" | ForEach-Object { $_ |Push-Location; try{ &npm install }finally{ Pop-Location }}
  •  Tags:  
  • Related