Use preinstall to run code before npm install. Don't try to override npm install in this fashion where you would end up with an infinite loop of calls to npm install.
You can also set environment variables using the config property of package.json. See docs for details