Giter VIP home page Giter VIP logo

nnms's Introduction

N&M's - Node and Micro services

N&M's is a NodeJS framework working with Typescript. It provides a flexible architecture to coordinate the different modules of an application solution.

N&M's allows developers to quickly start a new micro-services project and focus on features because of the built-ins to process common tasks.

Installation

N&M's delivers a core package, nnms, which holds all the core functionalities of the framework. In most of the cases, it will be needed to install specific packages to extend the possibilities of the framework, for example to bind a HTTP server on a module, the installation of the nnms-http will be necessary.

npm install --save nnms
[npm install --save nnms-http]

Core concept

The architecture of a N&M's application uses three main objects: provider, module and plugin.

Provider

A Provider represents a global service that can be injected into a module, plugin or other provider. A singleton is created during the application bootstrap then shared between all the objects in the application.

Module

A Module represents a entry point into a isolated scope of services. It is possible to inject a provider into module but it is not possible to inject other module. In many cases, modules are bounded to one or more servers to communicate internally and externally.

Plugin

A Plugin represents a extension of a module. By declaring a plugin on a module, a lot of common functionalities will become available using decorators on methods or parameter of the module class. For example, a plugin can bind a method to a http route or a broker subject.

Getting started

To start a N&M's project, you need to declare at least one module, then bootstrap it.

  // index.ts
  import { ModuleRef } from 'nnms'
  import { HttpPlugin } from 'nnms-http'

  const WEB_VARS = {LOCALE: '', HTTP_PORT: '8080'}

  @ModuleRef('web', WEB_VARS, HttpPlugin)
  class WebModule {
    constructor(
      private readonly _ctx: ModuleContext
    ) { }

    @HttpRoute({resType: 'string'})
    hello() {
        return this._ctx.vars.LOCALE === 'fr' ? 'Bonjour' : 'Hello'
    }
  }

  bootstrap({name: 'getting-started'}, WebModule)

The first step is to declare a class decorated with ModuleRef.

It is required to set a unique name ('web') for the module as the first argument.

The second argument describes the variables used by the module.

The following arguments represents the plugins (HttpPlugin) bounded to the module.

Declaring the plugin, allows to use its decorator (HttpRoute) to provide some functionalities for the module.

Here, HttpRoute registers the route on HttpPlugin, and then HttpPlugin tells HttpProvider to start a server.

To run the module, execute the following commands:

  tsc -p tsconfig.json
  WEB_LOCALE=fr node ./index.js

Then access to the http route:

  curl localhost:8080
  # Bonjour

nnms's People

Stargazers

Roman avatar  avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.