mm-service-register

1.0.7 • Public • Published

mm-service-register

A simple library to register and deregister services with Consul.

Installation

npm install mm-service-register

Envirorment .env

SERVICE_REGISTER=true SERVICE_REGISTER_PORT=8500 SERVICE_REGISTER_HOST=127.0.0.1 SERVICE_REGISTER_SCHEME=http

Example 1: Auto register / deregister with default values

const express = require('express'); const app = express(); const servicePort = 3001;

// Route app.use(/api/v1/health, (req, res) => { res.json({ status: 'running' }); });

// Server const server = app.listen(servicePort, () => { console.log('Now listening at port ' + servicePort); });

// Service register const ConsulRegister = require('mm-service-register'); new ConsulRegister().use(server); // default http://ip:port/api/v1/health

Example 2: Auto register / deregister with Options

const express = require('express'); const app = express(); const servicePort = 3002;

// Route app.use(/api/v1/health, (req, res) => { res.json({ status: 'running' }); });

// Server const server = app.listen(servicePort, () => { console.log('Now listening at port ' + servicePort); });

// Service register const ConsulRegister = require('mm-service-register');

const options = { check: { HTTP:http://localhost:3002/api/v1/health }, } new ConsulRegister().use(server, options);

Example 3: Manual register / deregister

const express = require('express'); const app = express(); const servicePort = 3003; const ConsulRegister = require('mm-service-register'); //Route app.use(/api/v1/health, (req, res) => { res.json({ status: 'running' }); }); //other route

//Server app.listen(servicePort, async () => { console.log('Now listening at port ' + servicePort); const consulOptions= { host: '127.0.0.1', port: 8500, scheme: 'http', version:'v1' }; const consulRegister = new ConsulRegister(consulOptions); const serviceOptions = { id:'service-id', name:'service-name', check:{ HTTP:http://localhost:3003/api/v1/health, //must full path Interval: '10s', Timeout: '3s' }, meta:{ scheme: 'http' } } await consulRegister.registerService(serviceOptions); });

Package Sidebar

Install

npm i mm-service-register

Weekly Downloads

1

Version

1.0.7

License

ISC

Unpacked Size

16.3 kB

Total Files

6

Last publish

Collaborators

  • itetrant