node.js deployment: how to get notified by email when "npm install" fails

After each deployment through a GitHub webhook, I often end up ssh'ing into my server checking why my app isn't running. Most of the time it's because npm install failed due to weird network issues.

In my package.json I have these scripts at the moment:

"scripts": {
  "start": "node ./src/server",
  "test": "gulp test",
  "deploy": "npm prune && npm install && gulp",
  "deploy-dev": "npm run-script deploy && pm2 startOrRestart ./etc/pm2/development.json"
}

I run deploy-dev which runs the deploy script. I want two improvements:

  • How can I get notified by email when the above npm install has failed? Is there a command for that?
  • Can I somehow automatically repeat npm install one minute only after it has failed?

Thanks for any advice!