Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including pm2-service-discovery with all npm packages installed. Try it out:

var pm2ServiceDiscovery = require("pm2-service-discovery")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

pm2-service-discovery v1.0.1

PM2 Module for Service Discovery

pm2-service-discovery

Synchronize services from consul to nodejs app managed by PM2.

How it works

This module propagate services changes using an event bus to services managed by PM2.

The module send config update to application :

  • Pragmatically when
    • PM2 start
    • PM2 launch a new service
    • Consul have a new configuration
  • Manually : pm2 trigger pm2-microservice reload

Sample

When the module is installed... in you code managed by pm2 :

process.on('message', (rs, err) => {
  if(err) return;
  if(rs && rs.topic === 'service:update') {
    const services = rs.data || [];

    console.log(JSON.stringify(services, null, 4));
  }
});

Configuration

keytypedefaultDescription
serviceenum(consul)consul
consulobject{}
consul.urlurlhttp://localhost:8500

Commands

reload : Ask Consul for config update

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free