node package manager
We need your input. Help make JavaScript better: Take the 2017 JavaScript Ecosystem survey »



Join the chat at

Build Status

PRs Welcome


Better NPM scripts runner

Inspired by


Usage in package.json

From this:

  "scripts": {
    "build:dist": "NODE_ENV=development webpack --config $npm_package_webpack --progress --colors",
    "test": "NODE_ENV=production karma start"

To this:

  "devDependencies": {
    "better-npm-run": "~0.0.1"
  "scripts": {
    "build:dist": "better-npm-run build:dist",
    "build:prod": "better-npm-run build:prod",
    "test": "better-npm-run test"
  "betterScripts": {
    "build:dist": "webpack --config $npm_package_webpack --progress --colors",
    "build:prod": {
      "command": "webpack --config $npm_package_webpack --progress --colors",
      "env": {
        "NODE_ENV": "production"
    "test": {
      "command": "karma start",
      "env": {
        "NODE_ENV": "test"

The betterScripts script definition can either be a string or sub-object with command and env attributes. Values defined in the env block will override previously set environment variables.

.env File

If you have an .env file in your project root it will be loaded on every command.


Environment variables defined in the betterScripts script definition will take precedence over .env values.

Shell scripts

Currently, using bash variables (PWD, USER, etc.) is not possible:

  "command": "forever start -l ${PWD}/logs/forever.log -o ${PWD}/logs/out.log -e ${PWD}/logs/errors.log -a index.js",

In order to use them, you can create an script file (.sh) instead:

forever start -l ${PWD}/logs/forever.log -o ${PWD}/logs/out.log -e ${PWD}/logs/errors.log -a index.js


  "command": "./"

cli commands

This module expose 2 cli commands:

  • better-npm-run and,
  • a shorter one: bnr which is an alias to the former.

The shorter one is useful for cases where you have a script that calls several better-npm-run scripts. e.g:

using the normal cli name

"scripts": {
  "dev": "shell-exec 'better-npm-run install-hooks' 'better-npm-run watch-client' 'better-npm-run start-dev' 'better-npm-run start-dev-api' 'better-npm-run start-dev-worker' 'better-npm-run start-dev-socket'",

using the shorter alias

"scripts": {
  "dev": "shell-exec 'bnr install-hooks' 'bnr watch-client' 'bnr start-dev' 'bnr start-dev-api' 'bnr start-dev-worker' 'bnr start-dev-socket'",

And for silence output, you can use -s or verbose --silence flags

bnr -s watch-client

And you can use -p or verbose --path to specify a custom path of dotenv file

bnr --path=/custom/path/to/your/env/vars start-dev

Also use -e or verbose --encoding to specify the encoding of dotenv file

bnr --encoding=base64 start-dev

See envdot docs for more infomation