Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/amauryd/env-file-rw
Write and read .env files
https://github.com/amauryd/env-file-rw
dotenv env environment-variables read typescript write
Last synced: 2 months ago
JSON representation
Write and read .env files
- Host: GitHub
- URL: https://github.com/amauryd/env-file-rw
- Owner: AmauryD
- License: mit
- Created: 2019-08-13T12:19:27.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-06T06:43:41.000Z (almost 2 years ago)
- Last Synced: 2024-10-15T13:26:17.211Z (3 months ago)
- Topics: dotenv, env, environment-variables, read, typescript, write
- Language: TypeScript
- Homepage:
- Size: 193 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# env-file-rw [![tests](https://github.com/AmauryD/env-file-rw/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/AmauryD/env-file-rw/actions/workflows/main.yml)
Edit and read from .env files# Features
- Read key from .env file
- Write key/value to .env file
- Preserve comments
- Typescript
- 0 dependencies# Sync example
```js
const EnvFileWriter = require("env-file-rw").default;
const envFileWriter = new EnvFileWriter("test.env");envFileWriter.get("HELLO","NOT WORLD");// NOT WORLD BY DEFAULT
envFileWriter.set("HELLO","WORLD");
// note : unsaved changes are not readable with .get()
// persists the changes
envFileWriter.saveSync();
```# Async example
```js
const EnvFileWriter = require("env-file-rw").default;
const envFileWriter = new EnvFileWriter("test.env",false); // false prevents direct sync parsing// open the file and parse it
await envFileWriter.parse();envFileWriter.get("HELLO","NOT WORLD");// NOT WORLD BY DEFAULT
envFileWriter.set("HELLO","WORLD");
// note : unsaved changes are not readable with .get()
// persists the changes
await envFileWriter.save();
```# Typescript example
```ts
import EnvFileWriter from "env-file-rw";
const envFileWriter = new EnvFileWriter< { HELLO : any} >("test.env",false); // you can specify the structure of the env file for the get()// open the file and parse it
await envFileWriter.parse();envFileWriter.get("HELLO","NOT WORLD");// NOT WORLD BY DEFAULT
envFileWriter.set("HELLO","WORLD");
// note : unsaved changes are not readable with .get()
// persists the changes
await envFileWriter.save();
```