NodeMicro

  • Apis
  • Config
  • Service Discovery and Config manager
  • Resources

APIs

Fill this in all routes beginning /api/v1 go to file ./api/v1/index.js

Config

Go to the config tab and set it with what ever info

Service Discovery and Config manager

API

var lsq = require('lsq')

All methods are asynchronous, and take a node-style error-first callback as last argument. If no callback is supplied, a promise is returned instead.

Service Discovery

lsq.services.list() -> Array

Returns all the currently known service names.

lsq.services.get(service: String) -> Service

Retrieves a particular service.

Example:

  lsq.services.get("email")
    .then(function(service){
       request.post('http://'+service+'/api/v1/demo/email'
        ,{json:req.body}
        , function (error, response, body) {
          if(error){
            console.error('can not reach email service')
            return res.send(500,{error:error,result:'can not reach email service'})
          } 
          res.send({result:"email sent"})
        })
    })

or

  lsq.services.get("email",function(config){

    // returns a object 
    // {"hostname":"127.0.0.1", "port":3001, toString(): "127.0.0.1:3001" }
    // in a string it prints concat host and port

     request.post('http://'+service+'/api/v1/demo/email'
      ,{json:req.body}
      , function (error, response, body) {
        if(error){
          console.error('can not reach email service')
          return res.send(500,{error:error,result:'can not reach email service'})
        } 

        res.send({result:"email sent"})
      })
  })

Service

  • hostname: String // the hostname or IP address of the service
  • port: Integer // the port of the service
  • toString() { return this.hostname + ':' + this.port }

Config

lsq.config.get() -> JSON

Fetches the JSON configuration for the current service.

Example:

  lsq.config.get()
    .then(function(config){
      // returns a object {}
    })

or

  lsq.config.get(function(config){
     // returns a object {}
  })

Resources