Courses & TutorialsProgramming
Everything awesome for using npm as a build tool.
- Task Runners
- File Watchers
- Dev Servers
- Cross-platform Utilities
- Other Utilities
- Cross-platform Shell Reference
- Why we should stop using Grunt & Gulp – Blog post by Keith Cirkel.
- How to Use npm as a Build Tool – Sequel to Why we should stop using Grunt & Gulp.
- Why I Left Gulp and Grunt for npm Scripts – Article by Cory House.
- Helpers and tips for npm run scripts – Blog post by Michael Kühnel covering advanced topics.
- Advanced front-end automation with npm scripts – Talk at Nordic.js 2015 by Kate Hudson.
- How to create a build system with npm scripts – Video tutorial series on setting up a front-end build system.
Tools for running multiple commands or npm scripts in parallel or sequentially.
- script-runner – Simple task runner with a terse syntax.
- npm-run-all – Fully featured task runner.
- redrun – Expand scripts from package.json to improve execution speed.
Tools to watch your source files and run a build command whenever any of the files change.
- http-server – Simple zero-configuration command-line http server.
- live-server – Simple development http server with live reload capability.
Utilities to perform common command-line tasks without worrying about cross-platform compatibility.
- rimraf – Delete files or directories; like
- del-cli – Safer file and folder deletion.
- mkdirp – Create a directory, creating parent directories if needed; like
- cpr –
cp -rfor Node.js.
- cpy-cli – File/directory copying/renaming.
- copyfiles – Copy a list of files into a directory.
- sync-files –
rsync-like directory syncing with watch mode.
- echo-cli – Cross-platform
echowith JS escape sequence support.
- clear-cli – Clear the terminal.
- cross-env – Set environment variables for scripts, unix-style.
- cross-os – Run platform-specific npm scripts.
- ntee – Utility that reads from standard input and writes to standard output and files; like Unix
- catw – Print a file to stdout, with optional watch mode; sorta like Unix
- shx – Collection of common Unix utilities implemented in Node.js; example usage:
shx rm somefile.
- hashmark – Take contents of a file and output as new file with a hash in the name.
- gzip-size-cli – Get the gzipped size of a file or stdin.
- opn-cli – Open websites, files, executables, etc. with the user’s preferred application.
- headr – Add header / banner info to a file.
- Bower files CLI – Get main bower files on the command line.
- cli-error-notifier – Send native desktop notifications when npm scripts fail.
- screwy – The npm scripts GUI.
- Forrest – npm scripts desktop client.
- run-npm – Run locally-installed node module executables. Useful for debugging npm scripts.
- npm-quick-run – Quickly run npm scripts by prefix without typing the full name.
- edit-script – Edit npm scripts from the command line without worrying about JSON escaping.
- ntl – Interactive cli menu to list and run npm scripts.
Cross-platform Shell Reference
A quick reference of the shell operators & commands that work the same on Unix and Windows.
&&to run commands in sequence. If a command fails, the script exits.
|to pipe the stdout of one command into the stdin of the next. (
do-something | something else)
>to write the stdout of a command to a file. (
do-something > file)
<to send the contents of a file to a command’s stdin. (
command < file)
cd <dir>to change the current working directory to
<dir>. Note that
cdalone prints the current working directory on windows, but changes the working directory to
npm run Reference
You can use
npm run-script or
npm run; they both do the same thing, but
npm run is shorter.
- Run just
npm runto print a list of scripts.
npm run script(where
scriptis the name of your script) will run
postscript; in that order.
- You can’t nest
- You can’t nest
- You can pass arguments to your scripts by passing
npm run, followed by the arguments. Example: Given the script
"mocha": "mocha", you can run
npm run mocha -- --reporter xunit. This effectively runs
mocha --reporter xunit.
npm testis the same as running
npm run test. The same applies to
- You can run
npm run <script> -sto silence the default npm output (useful for calling a script within another script).