Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fabiospampinato/dotenv-jsonc
Simple library for loading your .env.json file containing JSONC.
https://github.com/fabiospampinato/dotenv-jsonc
dotenv json jsonc
Last synced: 20 days ago
JSON representation
Simple library for loading your .env.json file containing JSONC.
- Host: GitHub
- URL: https://github.com/fabiospampinato/dotenv-jsonc
- Owner: fabiospampinato
- License: mit
- Created: 2023-01-16T19:36:24.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-09-24T16:28:49.000Z (about 1 year ago)
- Last Synced: 2024-11-16T01:27:25.180Z (about 1 month ago)
- Topics: dotenv, json, jsonc
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# Dotenv JSONC
Simple library for loading your `.env.json` file containing JSONC.
## Overview
- You are expected to have a `.env.jsonc`, or `.env.json`, or `.env` file containing JSON, with optional comments in it, at the root of your current working directory.
- If none of those files are found this library will throw.
- When reading environment variables the file is simply only parsed with [`tiny-jsonc`](https://github.com/fabiospampinato/tiny-jsonc).
- When extending environment variables values are always casted to strings first.## Install
```sh
npm install --save dotenv-jsonc
```## Usage
Example `.env.json` file:
```jsonc
{
// You can use comments, if you want to
"S3_BUCKET": "BUCKET_NAME",
"S3_BUCKET_PASSWORD": "BUCKET_PASSWORD"
}
```Read the content of your `.env.json` file, without extending environment variables:
```ts
import Dotenv from 'dotenv-jsonc';console.log ( Dotenv ); // => { S3_BUCKET: "BUCKET_NAME", S3_BUCKET_PASSWORD: "BUCKET_PASSWORD" }
console.log ( process.env.S3_BUCKET ); // => undefined
console.log ( process.env.S3_BUCKET_PASSWORD ); // => undefined
```Read the content of your `.env.json` file, and extend environment variables:
```ts
import Dotenv from 'dotenv-jsonc/register';console.log ( Dotenv ); // => { S3_BUCKET: "BUCKET_NAME", S3_BUCKET_PASSWORD: "BUCKET_PASSWORD" }
console.log ( process.env.S3_BUCKET ); // => "BUCKET_NAME"
console.log ( process.env.S3_BUCKET_PASSWORD ); // => "BUCKET_PASSWORD"
```Just extend environment variables:
```ts
import 'dotenv-jsonc/register';console.log ( process.env.S3_BUCKET ); // => "BUCKET_NAME"
console.log ( process.env.S3_BUCKET_PASSWORD ); // => "BUCKET_PASSWORD"
```Simple, right?
## License
MIT © Fabio Spampinato