1.0.0 • Published 7 years ago

medialon-single-instance v1.0.0

Weekly downloads
1
License
UNLICENSED
Repository
-
Last release
7 years ago

#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