Use ENVs securely with encryption
npm install secure-env






Secure-env is a module that loads environment variables from a .env.enc file.A encryption tool that would helps you prevent attacks from [npm-malicious-packages][npm-malicious-packages].
Create a .env file in the root directory of your project. Add
environment-specific variables on new lines in the form of NAME=VALUE.
For example:
``dosini`
DB_HOST=localhost:27017
DB_USER=scott
DB_PASS=tiger
`bash`
$ npm install -g secure-env
$ secure-env .env -s mySecretPassword
Alternatively if you want this installed locally run the command as follows:
`bash`
$ ./node_modules/secure-env/dist/es5/lib/cli.js .env -s mySecretPassword
If you are running NPM > v5.2. You can use npx:
`bash`
$ npx secure-env .env -s mySecretPassword
A new encrypted file .env.enc will be created in your project root directory.You can delete the .env file after this,to prevent stealing.
`javascript
let secureEnv = require('secure-env');
global.env = secureEnv({secret:'mySecretPassword'});
`
That's it.
global.env now has the keys and values you defined in your .env file.
`javascript`
var db = require('db')
db.connect({
host: global.env.DB_HOST,
username: global.env.DB_USER,
password: global.env.DB_PASS
})
`bash`
$ secure-env --option
| Option | What does it do | Defaults |
| ------ | ------ | ------ |
| --secret |env.enc
| --out |aes256
| --algo |
| --decrypt | prints the decrypted text to stdout
#### Path
Default: .env
You can specify a custom path if your file containing environment variables is
named or located differently.
`js`
require('secure-env')({path:'/custom/path/to/your/env/vars'});
#### Decryption Algorithm
Default: aes256
You may specify the encryption algorithm for your file containing environment variables
using this option.
`js`
require('secure-env')({enc_algo:'aes256'});
#### Secret
Default: mySecret
Specify the secret Key which was used during encryption of raw file.Having a salt-hashed secret key is recommended.
`js`
require('secure-env')({secret:'mySecretPassword'});
Refer https://github.com/motdotla/dotenv/blob/master/README.md#parse
The parsing engine currently supports the following rules:
- BASIC=basic becomes {BASIC: 'basic'}#
- empty lines are skipped
- lines beginning with are treated as commentsEMPTY=
- empty values become empty strings ( becomes {EMPTY: ''})SINGLE_QUOTE='quoted'
- single and double quoted values are escaped ( becomes {SINGLE_QUOTE: "quoted"})MULTILINE="new\nline"
- new lines are expanded if in double quotes ( becomes
``
{MULTILINE: 'new
line'}JSON={"foo": "bar"}
- inner quotes are maintained (think JSON) ( becomes {JSON:"{\"foo\": \"bar\"}")trim
- whitespace is removed from both ends of the value (see more on ) (FOO=" some value " becomes {FOO: 'some value'}`)
G.md)
See LICENSE
Source-env uses these open source projects to work properly:
* [Minimist][minimist] - Argument parser without all the fanciful decoration.
Source-env is inspired from and also uses code references from these open source projects:
* [Dotenv][dotenv]
[npm-malicious-packages]:
[minimist]:
[dotenv]: