Programmatically running npm scripts

Sep 4, 2015

npm has become an essential part of my tool-chain, and I often use the scripts entry in lieu of build tools like Gulp or Grunt for small to medium sized projects. One issue that I’ve encountered is wanting to kick off tasks stored in the scripts without actually running npm on the shell. Googling did not lead to any easy answers, but the solution was readily apparent from the npm-clisource.

Once you have installed npm locally npm i npm --save [insert “Yo dawg…” reference here], you can require and use it: