O'Reilly logo

TypeScript Microservices by Parth Ghiya

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Registering a service instance

Let's start by taking clones of the first microservice from Chapter 2, Gearing up for the Journey. You can find the entire source code in the chapter-6/consul/consul-producer folder:

  1. Open up the Terminal and hit the following command:
npm install consul  @types/consul --save
  1. Now in Application.ts, we will initialize our Consul client. Write this code:
import * as Consul from 'consul';import { ConsulOptions } from 'consul';…let consulOptions: ConsulOptions =  { host: '127.0.0.1', port: '8500', secure: false, promisify: false }….let details =  {    name: 'typescript-microservices-consul-producer',    address: HOST,    check: { ttl: '10s', deregister_critical_service_after: '1m' },    port: appPort, id: CONSUL_ID  };let consul ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required