Load newrelic in a 12-factor environment with sane defaults.
npm install env-newrelic   
> Load newrelic in a 12-factor environment with sane defaults.
$ npm install env-newrelic --save
0. You avoid writing and maintaining the following:
if (process.env.NODE_ENV === 'production') require('newrelic');
> With the above methodology, you'll be forced to push code to change behavior that should be configuration driven. See The Twelve-Factor App page titled [Store config in the environment].
0. You avoid configuring a newrelic.js file for each app and start with sane defaults
NEW_RELIC_HOME = Project Root Directory
NEW_RELIC_ENABLED = true
NEW_RELIC_APP_NAME = package.name + - + process.env.NODE_ENV
NEW_RELIC_LOG_LEVEL = 'info'
##### Enable
Set the NEW_RELIC_LICENSE_KEY environment variable.
##### Disable
Set the NEW_RELIC_DISABLED environment variable to a truthy value (i.e. true, yes, 1, etc.).
##### Initialize
require('env-newrelic')()
# or
var newrelic = require('env-newrelic')()
> NEW_RELIC_NO_CONFIG_FILE will be set to true if a newrelic.js file is found in your package root.
A list of more environment variables can be found in the documentation page [Configuring Node.js with environment variables].
While the environment variables make using a newrelic.js file optional, there may be situations where you need it. A list of more configuration parameters can be found in the documentation page Node.js agent configuration.
For most apps, a newrelic.js file is not needed
###### .env
NEW_RELIC_LICENSE_KEY="…"
###### .env.test
NEW_RELIC_DISABLED=true
- [Configuring Node.js with environment variables]
- [Store config in the environment]
[Configuring Node.js with environment variables]: https://docs.newrelic.com/docs/agents/nodejs-agent/installation-configuration/configuring-nodejs-environment-variables
[Store config in the environment]: http://12factor.net/config