Deviopath › Node.js

npm Script Command

Easy · npm

Scripts in package.json run with npm run <name>. npm has shortcuts for the most common ones: npm start and npm test work without run.

Write a function npmCommand(pkg, script):

- if there is no scripts object, or it has no entry named script, return null

- for "start" and "test" return "npm start" / "npm test"

- otherwise return "npm run <script>"

(Simplified: real npm has a few more shortcuts, like npm stop, and npm start can work without a script.)

Next: Should It Log?