Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uniquely identify a process in node.js

Tags:

node.js

unix

What values available in node.js combined create a unique ID for each process on each server in node.js? Right now, I only know how to obtain the process id.

like image 563
Jonathan Ong Avatar asked Feb 13 '13 04:02

Jonathan Ong


1 Answers

Not sure what your requirements are but you could do a hash of (hostname + pid + timestamp):

const crypto = require('crypto');
const os = require('os');

const parts = [os.hostname(), process.pid, +(new Date)];
const hash = crypto.createHash('md5').update(parts.join(''));

hash.digest('hex'); // "56f0dec9b403c5aa19827326555d6a5b"
like image 116
maerics Avatar answered Oct 19 '22 03:10

maerics