Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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 (about 6 years ago)
- Last Synced: 2024-03-14T20:53:17.057Z (8 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
[![Travis](https://img.shields.io/travis/myungjaeyu/json-dotenv/master.svg)](https://travis-ci.org/myungjaeyu/json-dotenv)
[![NPM Version](https://img.shields.io/npm/v/json-dotenv.svg)](https://www.npmjs.com/package/json-dotenv)[![NPM Badge](https://nodei.co/npm/json-dotenv.png?downloads=true)](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)