We choose Node.js because we were planning to use two minifiers that required Node.js anyway, and we are looking into the possibility of using Node.js for future projects, so this hook was a good, low risk, place to work with Node.js and see how it will fit in at our business.
Getting Data from Git
If you’ve written git hooks before you know that any information passed to the hook is passed via stdin and not as parameters to the script. To get the data that git passes to the hook you need to include and use the readline node module.
Install readline and save it with your git hook project:
Include readline and parse the data from stdin:
Testing your Hook on the Command Line
I prefer to test my scripts on the command line. I also find it helpful to be able to run the deployment process manually should something fail. You can make it possible to run the hook on the command line by accepting command line parameters in your Node.js script. You can do this by adding and requiring commander.
When I started this project I took inspiration from Git Hooks for the Front End Developer by Bradly Gore.