All Projects → ph0bos → Express Microservice Starter

ph0bos / Express Microservice Starter

Licence: isc
An express-based Node.js API bootstrapping module for building microservices.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Express Microservice Starter

Node Rem
Node REM - NodeJS Rest Express MongoDB and more: typescript, passport, JWT, socket.io, HTTPS, HTTP2, async/await, nodemailer, templates, pagination, docker, etc. Live Demo: https://node-rem-ngduc.vercel.app
Stars: ✭ 192 (+262.26%)
Mutual labels:  microservices, express
Node Typescript Boilerplate
Minimalistic project template to jump start a Node.js back-end application in TypeScript. ESLint, Jest and type definitions included.
Stars: ✭ 1,061 (+1901.89%)
Mutual labels:  microservices, express
Express Rest Boilerplate
⌛️ Express starter for building RESTful APIs
Stars: ✭ 1,794 (+3284.91%)
Mutual labels:  microservices, express
Whatsmars
Java生态研究(Spring Boot + Redis + Dubbo + RocketMQ + Elasticsearch)🔥🔥🔥🔥🔥
Stars: ✭ 1,389 (+2520.75%)
Mutual labels:  microservices, zookeeper
Surging
Surging is a micro-service engine that provides a lightweight, high-performance, modular RPC request pipeline. The service engine supports http, TCP, WS,Grpc, Thrift,Mqtt, UDP, and DNS protocols. It uses ZooKeeper and Consul as a registry, and integrates it. Hash, random, polling, Fair Polling as a load balancing algorithm, built-in service gove…
Stars: ✭ 3,088 (+5726.42%)
Mutual labels:  microservices, zookeeper
Devicehive Java Server
DeviceHive Java Server
Stars: ✭ 241 (+354.72%)
Mutual labels:  microservices, zookeeper
Nxplorerjs Microservice Starter
Node JS , Typescript , Express based reactive microservice starter project for REST and GraphQL APIs
Stars: ✭ 193 (+264.15%)
Mutual labels:  microservices, express
Spring Cloud Zookeeper
Spring Cloud Zookeeper
Stars: ✭ 481 (+807.55%)
Mutual labels:  microservices, zookeeper
Zheng
基于Spring+SpringMVC+Mybatis分布式敏捷开发系统架构,提供整套公共微服务服务模块:集中权限管理(单点登录)、内容管理、支付中心、用户管理(支持第三方登录)、微信平台、存储系统、配置中心、日志分析、任务和通知等,支持服务治理、监控和追踪,努力为中小型企业打造全方位J2EE企业级开发解决方案。
Stars: ✭ 16,163 (+30396.23%)
Mutual labels:  microservices, zookeeper
Nodebestpractices
✅ The Node.js best practices list (December 2021)
Stars: ✭ 72,734 (+137133.96%)
Mutual labels:  microservices, express
Nestjs
A collection of badass modules and utilities to help you level up your NestJS applications 🚀
Stars: ✭ 475 (+796.23%)
Mutual labels:  microservices, express
Sitewhere
SiteWhere is an industrial strength open-source application enablement platform for the Internet of Things (IoT). It provides a multi-tenant microservice-based infrastructure that includes device/asset management, data ingestion, big-data storage, and integration through a modern, scalable architecture. SiteWhere provides REST APIs for all system functionality. SiteWhere provides SDKs for many common device platforms including Android, iOS, Arduino, and any Java-capable platform such as Raspberry Pi rapidly accelerating the speed of innovation.
Stars: ✭ 788 (+1386.79%)
Mutual labels:  microservices, zookeeper
Actor4j Core
Actor4j is an actor-oriented Java framework. Useful for building lightweighted microservices (these are the actors themselves or groups of them). Enhanced performance of message passing.
Stars: ✭ 48 (-9.43%)
Mutual labels:  microservices
Cells
Future-proof content collaboration platform
Stars: ✭ 1,059 (+1898.11%)
Mutual labels:  microservices
Celebrate
A joi validation middleware for Express.
Stars: ✭ 1,041 (+1864.15%)
Mutual labels:  express
Jobeir
Building the future of tech jobs search
Stars: ✭ 47 (-11.32%)
Mutual labels:  express
Sessionstore
Sessionstore is a node.js module for multiple databases. It can be very useful if you work with express or connect.
Stars: ✭ 52 (-1.89%)
Mutual labels:  express
Cronner
Cronner 是一个分布式定时任务框架,支持作业依赖、分片、失效转移、集中配置和监控。
Stars: ✭ 51 (-3.77%)
Mutual labels:  zookeeper
Jaeger Client Go
Jaeger Bindings for Go OpenTracing API.
Stars: ✭ 1,035 (+1852.83%)
Mutual labels:  microservices
Nff Go
NFF-Go -Network Function Framework for GO (former YANFF)
Stars: ✭ 1,036 (+1854.72%)
Mutual labels:  microservices

Express Microservice Starter

An express-based bootstrapping module for building microservices with Node.js. The starter utilises sub-app mounting to provide any implementing express application with a variety of functionality.

NPM

Key Features

The starter provides the following features out of the box;

  • CORS support
  • Cache-Control header support
  • Body-parsing support
  • Configurable controller/route auto-scanning
  • Configurable health monitors
  • Configurable per-application logging
  • Automatic service registration with ZooKeeper
  • Actuator info and health endpoints (/info and /health)
  • Partial Response Powered by express-partial-response
  • Request correlation id support (res.locals.correlationId and req.log Bunyan child logging also provided)

Basic Usage

The following is the most basic usage of the starter, for a more detailed example please refer to the example directory;

'use strict';

var express = require('express');
var micro   = require('express-microservice-starter');

var app = express();

app.use(micro({ discoverable: false, debug: true }));

app.listen(8000, function onListen() {
  log.info('Microservice initialised and accepting requests at the following root: http://localhost:8000/starter/v1');
});

app.on('service:registered', function(data) {
  log.info('service registered with zookeeper', data);
  log.info('microservice registration data is also available as an app.locals property', app.locals.microservice);
});


Configuration

By placing an app.yml config file in the /config directory of an implementing app it is possible to override default options.

default:

  #
  # Basic
  #
  server:
    port: 8000

  #
  # Log
  #
  log:
    path: my-log-file.log

  #
  # Microservice
  #
  microservice:
    basePath: services
    server:
      name: starter/v1
      dependencies: my/other/service/to/monitor/v1
      registrationNetworkInterfacePriority: 
        - en0
        - lo0

  #
  # Zookeeper
  #
  zookeeper:
    connectionString: localhost:2181
    retry:
      wait: 1000
      count: 5

In the above example the application would be accessible at the following address: http://0.0.0.0:8000/starter/v1, with the /actuator/info and /actuator/health diagnostic endpoints activated.

Note: the registrationNetworkInterfacePriority property allows the selection of the network interface when dynamically registering a service with ZooKeeper.

Note: if registrationNetworkInterfacePriority doesn't work for you, you can set ADVERTISED_HOST and ADVERTISED_PORT environment variable.

If you would like to override the version which is exposed in the /info endpoint, just set the VERSION node env variable.

VERSION=1.0.1 node index.js

## API

app.use(micro([options]));

options is an optional argument which can overwrite the defaults. It can take the following properties;

  • debug: boolean Activate finer grained logging.
  • discoverable: boolean Register the service with Zookeeper to allow for discovery by other services connecting to the same instance of Zookeeper.
  • controllersPath: String Path to load controllers. Defaults to controllers.
  • monitorsPath: String Path to load monitors. Defaults to monitors.
  • partialResponseQuery: String The query parameter to use for partial reponse. Defaults to fields.
  • correlationHeaderName: String The name of your correlation header. Defaults to X-CorrelationID.
  • validatorOptions: object Enable express-validator with these options. Defaults to null.
  • enableBodyParsing: boolean Enable or disable body parsing, useful to disable when dealing with content other than JSON. Enables express-validator. Defaults to true.
  • enableEtag: boolean Activate etag. Defaults to false.
  • enableRequestTracing: boolean Enabled request log trace. Defaults to false.

SWAGGER Integration

Supports binding of route handlers using a swagger specification document via the options.swaggerConfig object.

app.js

'use strict';

var express = require('express');
var micro   = require('express-microservice-starter');

var app = express();

var options = {
  swaggerConfig: {
    filePath: `/swagger.yml`, // path to swagger specification file
    controllers: `lib/controllers` // path to controllers directory
  }
};

app.use(micro(options));

//  to register application specific exception handlers wait until the
//  'swagger:routes:registered' event is emitted.
app.once('swagger:routes:registered', () => {

  app.use(function (err, req, res, next) {
  
    if (err) {
      res.status(418).json({
        name: 'Teapot',
        message: 'Always wanted to use this...'
      });
    }
  });
});

app.listen(8000, function onListen() {
  log.info('Microservice initialised and accepting requests at the following root: http://localhost:8000/starter/v1');
});

swagger.yml

swagger: "2.0"
info:
  version: 1.0.0
  title: "API specification"
  description: API specification
basePath: /v1
schemes:
  - http
consumes:
  - application/json
produces:
  - application/json
paths:
  /users:
    x-swagger-router-controller: users # lib/controllers/users
    get:
      description: Return a list of users
      operationId: find
      responses:
        200:
          description: User Response
          schema:
            type: array
            items:
              $ref: '#/definitions/User'
        default:
          description: Standard Error Response
          schema:
            $ref: '#/definitions/Error'

  /users/{uuid}:
    x-swagger-router-controller: users # lib/controllers/users
    get:
      description: Return a user based on the provided uuid
      operationId: get
      parameters:
        - name: uuid
          in: path
          description: UUID of the user to return
          required: true
          type: integer
          format: int64
      responses:
        200:
          description: Item Response
          schema:
            $ref: '#/definitions/User'
        default:
          description: Standard Error Response
          schema:
            $ref: '#/definitions/Error'


definitions:
  User:
    required:
      - uuid
      - name
      - status
      - created
    properties:
      uuid:
        type: string
      name:
        type: string
      status:
        type: string
        enum:
          - active
          - inactive
      created:
          type: string
          format: date-time

lib/controllers/users.js

'use strict';

const user = {
  uuid: '1234567890',
  name: 'User One',
  status: 'active',
  created: new Date('2000-01-01')
};

exports.find = function find (req, res, next) {

  try {
    res.json([user]);
  }
  catch (e) {
    next(e);
  }
}

exports.get = function get (req, res, next) {

  try {
    res.json(user);
  }
  catch (e) {
    next(e);
  }
}

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].