-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c754856
commit e84cb23
Showing
1 changed file
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,51 @@ | ||
|
||
# fastify-dotenv | ||
<h1 align="center">fastify-dotenv</h1> | ||
<p align="center"><project-description></p> | ||
|
||
fastify-dotenv iterate over your .env file and converts it to a **decorator** named *env* | ||
|
||
|
||
|
||
|
||
## simple demo | ||
|
||
|
||
<img src="assets/image.png"> | ||
|
||
## Usage/Examples | ||
|
||
```javascript | ||
|
||
const Fastify = require('fastify').fastify; // i used v3.21.6 here | ||
const fastify = Fastify(); | ||
const dotenv = require('@hadimardanian/fastify-dotenv'); | ||
|
||
fastify.register(dotenv, { | ||
path: '/config/.env', // (1) | ||
decorator: 'env' // (2) | ||
}) | ||
|
||
fastify.listen(4000, function serverListen() { | ||
console.log('server is running on port ' + fastify.env) | ||
}) | ||
|
||
``` | ||
|
||
|
||
|
||
## some tips | ||
|
||
- (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**" | ||
- the "**.env**" file: Its name could be everything. but its format must be plain text and content must be like following: | ||
|
||
|
||
|
||
### .env file content | ||
|
||
> port=4000 | ||
> mngodb=mongodb://localhost/mydb | ||
> NODE_ENV=production | ||
|