node-mu
A node.js minimalistic microservice framework. At this stage node-mu it is not yet production-ready. It is under heavy testing.
Release notes
v. 0.3.7: now use Reflet metadatas in ioc decorators.
v. 0.3.6: fixed a bug in request params validation.
v. 0.3.5: fixed timezone in logging timestamp and in health service information.
v. 0.3.3: we're back on GitHub!
v. 0.1.1: we introduce Inversion of Control using the inversify IoC container library.
We introduce the new Producer and Service concept. All of the node-mu components are now injectable thanks to the relative decorator functions:
- injectable
- component
- provider
- route
- controller
- service
- repository
- factoryFunction
- application
- inject
Installation
Using npm:
$ npm install --save node-mu
using Yarn:
$ yarn add node-mu
Example
config/default.yml
########################################################################
# Service configuration.
#
# This configuration will be overridden by the NODE_ENV profile you use,
# for example development.yml for development profile or production.yml
# for production a so on.
#
########################################################################
service:
group: Examples
name: SimplerService
version:
major: 0
minor: 0
status: 0 # 0: alpha, 1: beta, 2: release, 3: final
api:
endpoint:
port: 5001
baseRoutingPath: /api/v2
security:
enabled: true
jwt:
secret: configure-here-jwt-secret-for-the-service
expiration:
enabled: true
minutes: 13149000
management:
endpoint:
port: 5101
baseRoutingPath: /mgmt
health:
path: /health
full: true
jwt:
secret: configure-here-jwt-secret-for-the-service
expiration:
enabled: true
minutes: 13149000
# optional configuration to open a db connection
db:
client: mysql2
connection:
host: set-here-the-host-of-your-db
database: set-here-the-name-of-your-db-schema
user: set-here-the-user-name
password: set-here-the-user-password
charset: utf8
# optional configurtion to open and AMQP connection
amqp:
url: amqp://set-here-a-user:set-here-a-pwd@set-here-the-host:5672/set-here-a-VHOST
exchange:
name: set_here_the_name_of_an_exchange
events:
mapFile: set/here/your/json/file
log:
path: ../path/for/log/file
console: true|false
level: set-here-your-log-level_(INFO,DEBUG,...)
json: true|false
requests:
console: true|false
errors:
console: true|false
# should match your Git repo version
info:
version: your.service.version
events-map.json
{
"events": [
{
"name": "new_user",
"amqpConfig": {
"exchange": {
"name": "uaa_events",
"route": "uaa_new_user_route"
}
}
},
{
"name": "user_updated",
"amqpConfig": {
"exchange": {
"name": "uaa_events",
"route": "uaa_new_user_route"
}
}
},
{
"name": "user_removed",
"amqpConfig": {
"exchange": {
"name": "uaa_events",
"route": "uaa_new_user_route"
}
}
}
]
}
index.js
const build = ;const SimpleService = ; const start = async {; try const service = ; await service; catch err throw err; }; ;
simple-service.js
const container injectable component application inject = ioc;const DbConnectionManager Api AmqpConnectionManager EventsEmitter = Providers;const Application = Application;const SimpleRoute = ; moduleexports = ;
simple-route.js
'use strict'; const inject route = ioc;const Route = ;const SimpleController = ;const Joi = ; const path = '/simple'; moduleexports = ;
simple-controller.js
'use strict'; const inject controller = ioc;const ApiEventsEmitterController = Controllers;const SimpleBusinessService = ; moduleexports = ;
services/simple-business-service.js
'use strict' const inject service = ioc;const Service = ;const SimpleRepository = ; moduleexports = ;
user-model.js
'use strict'; const Model = Model;const Authority = ; static { return 'USERS'; } static { return type: 'object' required: 'login' 'activated' 'created_by' 'created_date' properties: id: type: 'bigInteger' login: type: 'string' minLength: 1 maxLength:50 password_hash: type: 'string' minLength: 1 maxLength: 60 first_name: type: 'string' minLength: 1 maxLength: 50 last_name: type: 'string' minLength: 1 maxLength: 50 email: type: 'string' minLength: 7 maxLength: 100 image_url: type: 'string' minLength: 1 maxLength: 256 activated: type: 'bit' lang_key: type: 'string' minLength: 2 maxLength: 6 activation_key: type: 'string' minLength: 1 maxLength: 20 reset_key: type: 'string' minLength: 1 maxLength: 20 created_by: type: 'string' minLength: 1 maxLength: 50 created_date: type: 'timestamp' reset_date: type: 'timestamp' last_modified_by: type: 'string' minLength: 1 maxLength: 50 last_modified_date: type: 'timestamp' ; } static { return authorities: relation: ModelManyToManyRelation modelClass: Authority join: from: 'user.id' through: from: 'user_authority.user_id' to: 'user_authority.authority_name' to: 'authority.name' ; } moduleexports = User;
authority-model.js
'use strict'; const Model = Model; static { return 'AUTHORITIES'; } static { return type: 'object' required: 'name' properties: name: type: 'string' minLength: 1 maxLength: 50 ; } static { return users: relation: ModelManyToManyRelation modelClass: __dirname + '/user-model' join: from: 'authority.name' through: from: 'user_authority.authority_name' to: 'user_authority.user_id' to: 'user.id' ; } moduleexports = Authority;
simple-repository.js
'use strict'; const repository = ioc;const Repository = ;const User = ; moduleexports = ;
License
Licensed under the MIT license.