Check if your code is running as an npm script
$ npm install --save is-npm
var isNpm = require('is-npm'); console.log(isNpm);
$ node foo.js #=> false $ npm run foo #=> true
MIT © Sindre Sorhus