npm scripts, explained!

What does the scripts property do?

Chances are high you’re using scripts if you’re using npm: Whenever you enter $ npm run <command> (which is a short version of $ npm run-script <command>) into the terminal, that’s a script being ran.

Real world usage

Lets say you’re using Mocha for unit testing. If you want to run your unit tests, you normally have to npm install -g mocha (the -g argument installs the package globally on your machine) to get access to the mocha terminal command. This allows you to run your unit tests in the terminal:

$ mocha *.test.js

npm scripts to the rescue!

Using npm scripts, we can specify Mocha as adevDependency in our package.json:

"devDependencies": {
"mocha": ""
"scripts": {
"test": "mocha *.test.js"



Technical cofounder of, creator of react-boilerplate, co-creator of 💅 styled-components and maintainer of KeystoneJS and micro-analytics.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store