1.0.8 • Published 6 years ago

node-file-env v1.0.8

Weekly downloads
12
License
MIT
Repository
github
Last release
6 years ago

💨NodeFileEnv : Fast, Simple and Lightweight

Loads your environment variables from .env file into process.env.
badgen badgen

$ npm i node-file-env --save

Usage

// First, create a file named .env in the root of your project
// Second, add variables on new lines in the form of : NAME=VALUE
// Example :
// DB_HOST=localhost
// DB_PORT='3306'

var nodeFileEnv = require('node-file-env') 
nodeFileEnv().load()
// process.env now has the keys and values you defined in your .env file.
// you can specify your own file path and file name
// Default: path.resolve(process.cwd(), '.env')
var nodeFileEnv = require('node-file-env')  
nodeFileEnv('myFolder/.myfile').load()

Methods

  • nodeFileEnv(filePath).load() : void
    Loads all the variables that are saved in the .env file into the process.env object.

  • nodeFileEnv(filePath).getEnvVars() : []
    Returns all the variables that are saved in the .env files.

// Example of output
[ 
  { key: 'DB_HOST', val: 'localhost' },
  { key: 'DB_PORT', val: '3306' } 
]
  • nodeFileEnv(filePath).deleteEnvVars() : void
    Removes all the process.env variables that are saved in the .env file.

Remark

  • Any environment variable that have already been set will not be overridden.
  • Default encoding : UTF8.
  • process.cwd() : returns the current working directory.
  • Access to variables use : process.env -> Example : process.envDB_HOST or process.env.DB_HOST

Notes

  • Require Node 10+.
  • All pull requests are welcome, feel free.

Related projects

  • NodeRM : remove all extra spaces and comments from file.

License

MIT

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago