medialon-single-instance
v1.0.0
Published
Simple Single App Instance Module
Downloads
4
Readme
#single-instance
Simple Single App Instance Module.
var SingleInstance = require( 'single-instance').SingleInstance;
var singInstance = new SingleInstance();
var _Instance = null;
singInstance.registerInstance( 4805, function( err, instance ) {
if ( err ) {
console.log( 'Register instance failed: '+ err );
} else {
console.log( 'Instance registered: ' + JSON.stringify( instance ) );
_Instance = instance;
}
});
... application core
if ( singInstance.unregisterInstance( _Instance ) == true ) {
console.log( 'Instance unregistered.');
} else {
console.log( 'Error unregistering instance' );
}
##Installation
$ npm install
##Principle
Registration of an instance is simply based on an ip port opened as a tcp server. Unregistering the instance simply send a message to this server to stop listening.
To avoid any foreign application to unregister the application, the message sent to the server includes a random key which is generated upon registering.
##dependencies
- nodejs
- crypto
- util
- net
- events