This is base on the https://www.npmjs.com/package/dotenv and support multiple environments file.
# with npm
npm install propsenv
# or with Yarn
yarn add propsenv
As early as possible in your application, require and configure propsenv.
## default
require('propsenv')()
## with options
require('propsenv')({
debug: true,
path: './your_env_path',
encoding: 'utf-8'
})
Create a env_<env>.properties
file in the root/env/ directory of your project. Add environment-specific variables on new lines in the form of NAME=VALUE
. For example:
HOST=localhost.local
USER=root
PASS=pass
ARRAY=1,item,3, true
You can also create multiple env_<env>.properties
file in the directory.
# <root>/env
env_dev.properties
env_test.properties
env_prod.properties
Then execute your start script before with NODE_ENV=, you will get the configured variables in to env_.properties file by process.env.HOST, process.env.USER, process.env.PASS
NODE_ENV=test node your_script.js