Skip to content

Commit

Permalink
listen and provide callback handler on SIGPIPE signal
Browse files Browse the repository at this point in the history
  • Loading branch information
przemek-nowicki committed May 4, 2022
1 parent 713f2e4 commit ab54a69
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 1 deletion.
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Logs #
/logs
*.log
*.log*

# Node files #
node_modules/
npm-debug.log
yarn-error.log

# OS generated files #
.DS_Store
Thumbs.db

# Typing #
typings/

# Dist #
dist/

# IDE #
.idea/
*.swp
.awcache

# Generated source-code #
src/**/*.js.map
coverage/
26 changes: 26 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Logs #
/logs
*.log
*.log*

# Node files #
node_modules/
npm-debug.log
yarn-error.log

# OS generated files #
.DS_Store
Thumbs.db

# Typing #
typings/

# IDE #
.idea/
*.swp
.awcache

# Generated source-code #
test/
coverage/

10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@

**RnR** - is tiny lib to refresh node setup on runtime without restarting the node server.

# Install

```sh
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.

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


32 changes: 32 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

let cbToCall;
const process = global.process

const isProcessOk = (process) => {
return process &&
typeof process === 'object' &&
typeof process.kill === 'function' &&
typeof process.pid === 'number' &&
typeof process.on === 'function'
}

const reloadCbFn = (cb) => {
cbToCall = cb;
};

process.on('SIGPIPE', () => {
if (typeof cbToCall === 'function') {
cbToCall();
} else {
console.error('SIGPIPE triggered but no callback provided to execute!');
}
});

if (!isProcessOk(process)) {
module.exports = () => {
return () => {}
}
} else {
module.exports = reloadCbFn;
}
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "runtime-node-refresh",
"version": "1.0.0",
"description": "Refresh node environment variables on runtime without restarting the node server.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/przemek-nowicki/runtime-node-refresh.git"
},
"keywords": [
"refresh",
"env",
"update",
"env",
"runtime",
"refresh",
"node",
"refresh",
"envs"
],
"author": "[email protected]",
"license": "ISC",
"bugs": {
"url": "https://github.com/przemek-nowicki/runtime-node-refresh/issues"
},
"homepage": "https://github.com/przemek-nowicki/runtime-node-refresh#readme"
}

0 comments on commit ab54a69

Please sign in to comment.