service-basic-pipservices
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

Basic Microservice in Node.js

This basic microservice executes simple requests.

Supported functionality:

  • Deployment platforms: Standalone Process, Docker
  • External APIs: Commandable HTTP, REST/HTTP, gRPC, Commandable gRPC
  • Health checks: Heartbeat, Status
  • Swagger: http://localhost:8080/swagger/index.html

Dependencies on infrastructure services:

  • (optional) ElasticSearch for logging
  • (optional) Prometheus Push Gateway for performance metrics
  • (optional) DataDog for logging and performance metrics

There are no dependencies on other microservices.

Quick links:

Contract

export class RequestV1 {
    public value: string;
}

export class ResponseV1 {
    public value: string;
}

interface IBasicController {
    doSomething(context: IContext, request: RequestV1): Promise<ResponseV1>;
}

Get

Get the microservice source from GitLab:

git clone git@bitbucket.org:entinco/eic-templates-services-node.git

Get docker image for the microservice:

docker pull entinco/service-basic-pipservices:latest

Run

The microservice can be configured using the environment variables:

  • AZURE_ENABLED - turn on Azure container
  • DATADOG_ENABLED - turn on DataDog loggers and metrics
  • DATADOG_PROTOCOL - (optional) connection protocol: http or https (default: https)
  • DATADOG_URI - (optional) resource URI or connection string with all parameters in it
  • DATADOG_HOST - (optional) host name or IP address (default: api.datadoghq.com)
  • DATADOG_PORT - (optional) port number (default: 443)
  • DATADOG_ACCESS_KEY - DataDog client api key
  • ELASTICSEARCH_LOGGING_ENABLED - turn on Elasticsearch logs and metrics
  • ELASTICSEARCH_PROTOCOL - connection protocol: http or https
  • ELASTICSEARCH_SERVICE_URI - resource URI or connection string with all parameters in it
  • ELASTICSEARCH_SERVICE_HOST - host name or IP address
  • ELASTICSEARCH_SERVICE_PORT - port number
  • DEFAULT_RESPONSE - default response from service if empty request
  • LAMBDA_ENABLED - turn on AWS lambda container
  • GCP_ENABLED - turn on Google Cloud Function container
  • GRPC_ENABLED - turn on GRPC endpoint
  • GRPC_PORT - GRPC port number (default: 8090)
  • HTTP_ENABLED - turn on HTTP endpoint
  • HTTP_PORT - HTTP port number (default: 8080)
  • PUSHGATEWAY_METRICS_ENABLED - turn on pushgetway for prometheus
  • PUSHGATEWAY_PROTOCOL - connection protocol: http or https
  • PUSHGATEWAY_METRICS_SERVICE_URI - resource URI or connection string with all parameters in it
  • PUSHGATEWAY_METRICS_SERVICE_HOST - host name or IP address
  • PUSHGATEWAY_METRICS_SERVICE_PORT - port number
  • SWAGGER_ROUTE - the path where the swagger service will be available
  • SWAGGER_NAME - the header name of swagger service
  • SWAGGER_DESCRIPTION - the text description of swagger service

Start the microservice as process:

node ./bin/main

Run the microservice in docker: Then use the following command:

./run.ps1

Launch the microservice with all infrastructure services using docker-compose:

docker-compose -f ./docker/docker-compose.yml

Use

Install the client NPM package as

npm install client-basic-node --save

Inside your code get the reference to the client library

 import { BasicCommandableHttpClientV1 } from 'client-basic-pipservices';

Instantiate the client

// Create the client instance
let client = new BasicCommandableHttpClientV1();

Define client configuration parameters.

// Client configuration
let httpConfig = ConfigParams.fromTuples(
    "connection.protocol", "http",
    "connection.host", "localhost",
    "connection.port", 3000
);
client.configure(httpConfig);

Connect to the microservice

// Connect to the microservice
await client.open(Context.fromTraceId("123"));

Create a new entity

let req: RequestV1 = {
    value: 'Bla bla bla'
};

res = await client.doSomething(Context.fromTraceId("123"), req);
console.log("Response: " + res.value);

Develop

For development you shall install the following prerequisites:

  • Node.js 14+
  • Visual Studio Code or another IDE of your choice
  • Docker

Install dependencies:

npm install

Compile the microservice:

tsc

Compile proto files:

npm run protogen

Before running tests launch infrastructure services and required microservices:

docker-compose -f ./docker-compose.dev.yml

Run automated tests:

npm test

Run automated benchmarks:

npm run benchmark

Run linter

npm run lint

Generate API documentation:

./docgen.ps1

Before committing changes run dockerized build and test as:

./protogen.ps1
./build.ps1
./test.ps1
./package.ps1
./run.ps1
./clean.ps1

Contacts

This microservice was created by and is currently maintained by Person Name.

Readme

Keywords

none

Package Sidebar

Install

npm i service-basic-pipservices

Weekly Downloads

1

Version

1.1.0

License

Commercial

Unpacked Size

814 kB

Total Files

485

Last publish

Collaborators

  • pipdeveloper