Skip to content

Instantly share code, notes, and snippets.

@rjungemann
Created October 8, 2010 18:46
Show Gist options
  • Save rjungemann/617308 to your computer and use it in GitHub Desktop.
Save rjungemann/617308 to your computer and use it in GitHub Desktop.
Generate UUIDs with uuidgen from Node
var sys = require("sys");
var events = require('events')
var childProcess = require('child_process');
var Uuid = function() {
var self = this;
this.generate = function() {
var child = childProcess.exec(
'uuidgen | tr [:upper:] [:lower:]',
function(error, stdout, stderr) {
self.emit('generate', stdout.match(/[\w-]+/));
if(error !== null) { console.log(error); }
}
);
}
};
sys.inherits(Uuid, events.EventEmitter)
module.exports = Uuid;
// // Example
//
// var sys = require('sys');
//
// var Uuid = require("./libs/uuid");
//
// var uuid = new Uuid();
//
// uuid.on('generate', function(data) {
// sys.print(data);
// });
// uuid.generate();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment