3.0.9 • Public • Published


    Build Status js-standard-style npm version Coverage Status

    An api to make it easy to deploy complete infrastructures of microservices using now


    npm install now-fleet --save

    Service Dependency

    We define service dependencies in package.json of each service. Let's say we have a service A depending on service B and C, package.json for A should have a services field as following:

      "services": {
        "serviceB": "^2.0.0",
        "serviceC": "^3.0.0"

    Let's say B also depends on C. Then package.json for B should have a services field as following:

      "services": {
        "serviceC": "^2.0.0"

    Service dependencies need a version like npm module dependencies. This version should be a published version of npm module for dependency service. For our example, service A depends on ^3.0.0 of C but service B depends on ^2.0.0 of C.

    Fleet Deployment

    We start deployment from the topmost service which depends on other services, for our example service A. Let's call it root service.

    export REGISTRY_HOST=""
    node_modules/.bin/now-fleet-deploy type=ENV_TYPE

    This script walks through all the services we depend on and dependencies of them recursively. Deploys them to now and gives us now url of root service.

    Root Service Decision

    Deployment script should run on a service considering dependency tree. It can only walk down from top and can't discover dependants magically. If there is a service in the stack which is not a dependency of any other service, it won't be discovered and should be deployed separately.

    Circular Dependency

    Circular dependencies are taken care at deployment time and all fine. A can depend on B and B can depend on A at the same time or while A depends on B and B depends on C; C can depend on A.


    Another version of root service can't be a dependency of any service in the tree. For example serviceA@2.0.0 is deployment root and depends on, service B and service C. This schema allows service B or C depending on serviceA@2.0.0 but not on serviceA@1.0.0.

    Service Discovery

    Each service should discover dependency urls on the boot time. This module provides a method for discovery.

    getServices(pkg, delay)

    Discovers host names of dependencies defined in package.json by polling the latest deployed services from now API. Takes care of finding the host name for the right version of the dependency service. Second parameter is the delay in miliseconds between each polling from now API. It'll repeat until discovering all the deployments.

    const fleet = require('now-fleet').fleet
    const pkg = require('./package.json')
    fleet.getServices(pkg, 2000)
      .then(pkg => {
        // pkg._services object has all the host names
        // pkg._services.serviceC is something like


    npm i now-fleet

    DownloadsWeekly Downloads






    Last publish


    • avatar