https://github.com/myungjaeyu/json-dotenv
json-dotenv
https://github.com/myungjaeyu/json-dotenv
Last synced: 3 months ago
JSON representation
json-dotenv
- Host: GitHub
- URL: https://github.com/myungjaeyu/json-dotenv
- Owner: myungjaeyu
- License: mit
- Created: 2018-05-24T04:06:17.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-11T07:23:40.000Z (over 6 years ago)
- Last Synced: 2024-03-14T20:53:17.057Z (11 months ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# json-dotenv
[](https://travis-ci.org/myungjaeyu/json-dotenv)
[](https://www.npmjs.com/package/json-dotenv)[](https://www.npmjs.com/package/json-dotenv)
```
npm i --save json-dotenv
```## Usage
Create an `.env.json` file at the root.
```json
{
"EXAMPLE_NAME" : "json-dotenv",
"EXAMPLE_PORT" : 3343,
"EXAMPLE_VERS" : 1.3011,
"EXAMPLE_LIST" : [
1,
2,
3
],
"EXAMPLE_OBJS" : {
"first" : 1,
"second" : 2,
"third" : {
"a" : 1,
"b" : 2,
"c" : {
"c_a" : 31,
"c_b" : 32,
"c_c" : 33
}
}
},
"npm_config_git" : "filtered"
}
```Set the variables into process.env.
```javascript
require('json-dotenv')(); // require('json-dotenv')('.env.json');console.log(process.env.EXAMPLE_NAME || '');
console.log(process.env.npm_config_git); // 'git'
```Assigning a property on process.env will implicitly convert the value to a string.
```javascript
console.log(JSON.parse(process.env.EXAMPLE_OBJS));
```## License
[MIT](LICENSE)