Creates a pid file and returns the filename, if an existing pid file does not exist, or the corresponding process for the pid in an existsing file is no longer running. Otherwise, it returns any empty string..
0.0.3 Added support for all node v8 platforms.
git clone git@github.com:donaldbales/node-pid.git
cd node-pid
npm install
./node_modules/.bin/tsc
You need to set these environment variables:
# Where to store the Process ID (PID) file
export PID_PATH=.
Using npm:
$ npm i --save node-pid
In Node.js:
const nodePid = require('node-pid');
// To create a pid file:
const pidFilename = await nodePid.create(logger, 'myPidFilename');
if (pifFilename) {
// Another process by this name is not running
// so go ahead and do your processing...
// All done: delete the pid file:
fs.unlinkSync(pidFilename);
} else {
// Sorry, already running!
process.exit(1);
}
Supports Node versions 8+.
Feel free to email don@donaldbales.com with and complaints and questions.