sails-js-hook-dotenv
Advanced tools
Comparing version 1.0.4 to 1.1.0
@@ -42,1 +42,8 @@ # CHANGELOG | ||
**Full Changelog**: https://github.com/ActuallyConnor/sails-js-hook-dotenv/compare/1.0.3...1.0.4 | ||
### 1.1.0 | ||
- Adding new config options | ||
- Adding new tests for new config options | ||
**Full Changelog**: https://github.com/ActuallyConnor/sails-js-hook-dotenv/compare/1.0.4...1.1.0 |
22
index.js
@@ -21,4 +21,22 @@ dotenv = require('dotenv') | ||
const result = dotenv.config() | ||
const config = {} | ||
if (sails.config[this.configKey].path !== undefined) { | ||
config['path'] = sails.config[this.configKey].path | ||
} | ||
if (sails.config[this.configKey].encoding !== undefined) { | ||
config['encoding'] = sails.config[this.configKey].encoding | ||
} | ||
if (sails.config[this.configKey].debug !== undefined) { | ||
config['debug'] = sails.config[this.configKey].debug | ||
} | ||
if (sails.config[this.configKey].override !== undefined) { | ||
config['override'] = sails.config[this.configKey].override | ||
} | ||
const result = dotenv.config(config) | ||
// dotenv config failed to load | ||
@@ -28,3 +46,3 @@ if (result.error) { | ||
if (sails.config[this.configKey].throwOnFailure) { | ||
throw result.error | ||
throw new Error('dotenv hook failed to load') | ||
} else { | ||
@@ -31,0 +49,0 @@ sails.config[this.configKey].active = false |
{ | ||
"name": "sails-js-hook-dotenv", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"description": "Sails.js hook for loading .env files", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# sails-js-hook-dotenv | ||
[Sails JS](http://sailsjs.org) hook to load environment variables from a `.env` file using [dotenv](https://github.com/motdotla/dotenv) | ||
[Sails JS](http://sailsjs.org) hook to load environment variables from a `.env` file | ||
using [dotenv](https://github.com/motdotla/dotenv) | ||
@@ -11,14 +12,19 @@ ### Installation | ||
Start sails as you normally do (`sails lift`) and you will be able to access your environment variables using `process.env.your-variable-name` | ||
Start sails as you normally do (`sails lift`) and you will be able to access your environment variables | ||
using `process.env.your-variable-name` | ||
### Configuration | ||
You can add configuration options for this hook in `config/dotenv.js` by default. Currently, the only option is a boolean: `active`. Setting this to false will disable this hook. | ||
You can add configuration options for this hook in `config/dotenv.js` by default. Currently, the only option is a | ||
boolean: `active`. Setting this to false will disable this hook. | ||
```js | ||
module.exports.dotenv = { | ||
default: { | ||
/** | ||
* Setting this to false will disable this hook | ||
* | ||
* Default: true | ||
*/ | ||
@@ -28,9 +34,43 @@ active: true, | ||
/** | ||
* Setting this to false will cause the application | ||
* Setting this to false will cause the application | ||
* NOT to throw an error if the config fails to load | ||
* | ||
* Default: true | ||
*/ | ||
throwOnFailure: true, | ||
/** | ||
* Specify a custom path if your file containing | ||
* environment variables is located elsewhere. | ||
* | ||
* Default: path.resolve(process.cwd(), '.env') | ||
*/ | ||
path: '/custom/path/to/.env', | ||
/** | ||
* Specify the encoding of your file containing | ||
* environment variables. | ||
* | ||
* Default: utf8 | ||
*/ | ||
encoding: 'latin1', | ||
/** | ||
* Turn on logging to help debug why certain keys | ||
* or values are not being set as you expect. | ||
* | ||
* Default: false | ||
*/ | ||
debug: true, | ||
/** | ||
* Override any environment variables that have | ||
* already been set on your machine with values | ||
* from your .env file. | ||
* | ||
* Default: false | ||
*/ | ||
override: true, | ||
} | ||
} | ||
@@ -37,0 +77,0 @@ ``` |
12859
18
166
86