Juraj Jakubov
Juraj Jakubov

Reputation: 261

Run npm command in exact folder with powershell

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?

Upvotes: 0

Views: 408

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174485

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 }}

Upvotes: 1

Related Questions