## Nodefony® {{nodefony.version}}

### Microservices Get Started

    const nodefony = require("nodefony");
    const path = require("path");
    const Server = require(path.resolve("src", "node", "services", "servers", "http.js"));

    class Service extends nodefony.Service {

      constructor(environment = "production", debug = false) {
        super("Microservice");
        this.environment = environment;
        this.debug = debug;
        // init logger
        this.initSyslog();
        this.log(`Environment = ${environment}   Debug = ${debug}`);
        this.settings = require(path.resolve("config", "config.js"));
        // start
        this.start();
      }

      async start() {
        return await this.startHttpServer();
      }

      async startHttpServer(){
        const http = new Server(this);
        // add in service container
        this.set("http", http);
        return await http.start();
      }

      stop(code) {
        return new Promise((resolve, reject)=>{
          process.nextTick(() => {
            this.log("Life Cycle Terminate");
            try {
              if (code === 0) {
                process.exitCode = code;
              }
              return resolve(process.exit(code));
            } catch (e) {
              this.log(e, "ERROR");
              return reject(e);
            }
          });
        });
      }
    }

    module.exports = new Service(process.env.NODE_ENV, process.env.DEBUG);