Skip to content

Latest commit

 

History

History
61 lines (52 loc) · 1.37 KB

README.md

File metadata and controls

61 lines (52 loc) · 1.37 KB

This is local package (not publishing).

Node.js Process Life Manager for Server

This is a manager that can call events when a Node process starts or dead.
Compatible with Ctrl+C, nodemon and heroku.

Getting Started

  1. Install node-process-life-manager using npm:
npm i insell824/node-process-life-manager
  1. Import insell-node-process-life-manager and create server.
  • app.js
const http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World!\n');
}).listen(1337, '127.0.0.1');

const processLife =  require('insell-node-process-life-manager')
processLife.addEndListener(function () {
  return new Promise(function (resolve, reject) {
    console.log('Async Process completed.')
    resolve()
  })
})

processLife.addEndListener(function () {
  return new Promise(function (resolve, reject) {
    console.log('Async Process refused.')
    reject(new Error('ErrorMessage(Test)!'))
  })
})

processLife.addEndListener(function () {
  console.log('Process completed.')
})
  1. Command line.
node ./app.js
  1. Keyboard. Press Ctrl+C keys and finish the server.

  2. Command line.

Process completed.
Async Process refused.
Error: ErrorMessage(Test)!
  ...
Async Process completed.

Uninstall

npm uni insell-node-process-life-manager