Skip to content

Commit

Permalink
docs: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Feb 16, 2022
1 parent d38600d commit af016e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ The intention behind this repository is to always maintain a viable and simple E
`@secjs/env` uses `dotenv` library to find .env file in the project root, you can run your application with environment `NODE_ENV` set
and `@secjs/env` will try to find the `.env.${NODE_ENV}`.

> Example
```bash
NODE_ENV=testing node index.js
```

If index.js file is using Env function the singleton of environment will run and find verify is exists
NODE_ENV. In this case `@secjs/env` will use .env.testing file.

<img src=".github/env.png" width="200px" align="right" hspace="30px" vspace="100px">

## Installation
Expand All @@ -40,20 +31,29 @@ NODE_ENV. In this case `@secjs/env` will use .env.testing file.
npm install @secjs/env
```

## Example

```bash
NODE_ENV=testing node index.js
```

If index.js file is using Env function the singleton of Env will run and verify if exists
NODE_ENV. In this case Env will use .env.testing file.

## Usage

> You can use Env function as a global importing just one time the global file
> You can use Env function as a global importing just one time the global file. Global already call resolveEnvFile function.
```ts
import '@secjs/env/src/utils/global.ts'

Env('DB_DATABASE', 'my-database')
```

> Or you can call directly the Env function
> Or you can call directly the Env function, but first you will need to call resolveEnvFile to get the env file by NODE_ENV.
```ts
import { Env } from '@secjs/env'
import { Env, resolveEnvFile } from '@secjs/env'

// Simulating .env file
HOST='127.0.0.1'
Expand All @@ -63,6 +63,9 @@ DB_DEBUG=false
DB_DATABASE='database'
APP_URL='http://${HOST}:${PORT}'

// Important to resolve env file
resolveEnvFile()

// The response value will be the value of DB_DATABASE variable or my-database by default
const db = Env('DB_DATABASE', 'my-database')
console.log(db) // 'database'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@secjs/env",
"version": "1.2.8",
"version": "1.2.9",
"license": "MIT",
"author": "João Lenon",
"repository": "https://github.com/SecJS/Env.git",
Expand Down

0 comments on commit af016e0

Please sign in to comment.