Microservice is apart of Microframework modules.
This module give you abilities to create microservice from any local object/module. All public functions will be available to call from external.
Installation
npm install mf-microserivce
This module require Node.js > 0.12.x
Require mf-microservice
const microService = require('mf-microservice');
Prepare your object or using any existed object
//Example object
var example = {
getName: function () {
return { name: 'example' };
},
getVersion: function () {
return { version: '1.0.1' };
},
_protected: function () {
return { message: 'This function shouldn\'t available' };
},
getParams: function () {
var data = [];
for(i in arguments){
data.push(arguments[i]);
}
return data;
}
}
Use Microservice to provide service from the object
//Implement microservice with cluster support
var app = microService(example);
if (cluster.isMaster) {
for (var i = 0; i < 4; i++) {
cluster.fork();
}
cluster.on('exit', (worker, code, signal) => {
console.log(`Worker ${worker.process.pid} died`);
});
} else {
app.server.listen(8080);
}
This module public under MIT License