Skip to content

Commit

Permalink
provide usage example
Browse files Browse the repository at this point in the history
  • Loading branch information
przemek-nowicki committed May 5, 2022
1 parent 7a98800 commit 682821a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,52 @@ npm install --save runtime-node-refresh

# Usage

It may be very usefult when you want to refresh/update your environment variables let's say your log level without restarting node server.
Following you will find

Create `index.js` file and add the following code:

```javascript
import RnR from 'runtime-node-refresh';

process.env.LOG_LEVEL = 'error';

RnR(() => {
process.env.LOG_LEVEL = 'debug';
});

setInterval(() => console.log(`The LOG_LEVEL is set to ${process.env.LOG_LEVEL}`), 5000);
```

Create `package.json' file and fill it with the following:
```json
{
"name": "test-rnr",
"scripts": {
"start": "node index.js",
"refresh": "runtime-node-refresh"
},
"dependencies": {
"runtime-node-refresh": "^1.0.3"
}
}
```

Open two terminals, in the first terminal execute:

```sh
npm start
```


And run the refresh task in second terminal:

```sh
npm run refresh
```

## Real life example:

It may be very usefult when you want to restart/update environment variable on running node application without restarting the node server.

Note: RnR is using node signals which means it does not work on Worker threads.

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": "runtime-node-refresh",
"version": "1.0.3",
"version": "1.0.4",
"bin": "./bin/rnr.js",
"description": "Refresh node environment variables on runtime without restarting the node server.",
"main": "index.js",
Expand Down

0 comments on commit 682821a

Please sign in to comment.