# @hadimardanian/fastify-dotenv

> fastify-dotenv iterate over your .env file and converts it to a **decorator** named *env*

Latest version **1.0.3** (published 2021-10-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install @hadimardanian/fastify-dotenv
pnpm add @hadimardanian/fastify-dotenv
yarn add @hadimardanian/fastify-dotenv
bun add @hadimardanian/fastify-dotenv
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2021-10-03 |
| First published | 2021-09-29 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 98.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Hadi |
| Maintainers | hadi-ma |

## Links

- npm: https://www.npmjs.com/package/@hadimardanian/fastify-dotenv
- Repository: https://github.com/HadiMardanian/fastify-dotenv
- Homepage: https://github.com/HadiMardanian/fastify-dotenv#readme
- Issues: https://github.com/HadiMardanian/fastify-dotenv/issues
- npm.io page: https://npm.io/package/@hadimardanian/fastify-dotenv

## Dependencies (3)

- [fastify-error](https://npm.io/package/fastify-error.md) ^0.3.1
- [fastify-plugin](https://npm.io/package/fastify-plugin.md) ^3.0.0
- [fastify-warning](https://npm.io/package/fastify-warning.md) ^0.2.0

## Recent versions

- 1.0.3 (latest) — 2021-10-03
- 1.0.2 — 2021-10-03
- 1.0.1 — 2021-10-03
- 1.0.0 — 2021-10-03
- 1.0.0-beta.1 — 2021-10-03
- 0.0.1 — 2021-09-30
- 0.0.0 — 2021-09-29

## README

# fastify-dotenv

### The fastify-dotenv iterates over your .env file and make it a **decorator**.

## Usage/Examples

### 1 ) DEFAULT way
```javascript

const Fastify = require('fastify').default,
    server = Fastify(),
    dotenv = require('@hadimardanian/fastify-dotenv');

server.register(dotenv, {
    path: '/config/.env', // (1)
    decorator: 'env' // (2)
});

server.listen(3000, function () {
    console.log('server is running on port ' + fastify.env);
});

```


  
## Description

- (1) **path** : the "**/**" means the root of project folder. it must be at the beginning of path.
- (2) **decorator** : name it whatever you want, if omitted it will be "**env**" and if set it to *```false```* will not set.
- the "**.env**" file: Its name could be whatever you want. but its format must be plain text and content must be like following:


  
### .env file content

> PORT=3000 <br>
MONGO_CONNECTION=mongodb://localhost/mydb <br>
NODE_ENV=production

And in general ...
> KEY=VALUE
<hr>

### 2 ) Specifying the project directory
```javascript

const Fastify = require('fastify').default,
    server = Fastify(),
    dotenv = require('@hadimardanian/fastify-dotenv');

server.register(dotenv, {
    path: '/config/.env',
    root: '/home/me/Documents/projects/nodeApp'
});

server.listen(3000, function () {
    console.log('server is running on port ' + fastify.env);
});

```
## Description
### Sometime for any reason you start node process somewhere not in the root of the project directory. Then you must manully specify the root of project folder in *```root```* parameter.

---
_Source: https://npm.io/package/@hadimardanian/fastify-dotenv · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
