const logger = require('./libs/logger.js'); const api = require('./libs/api.js'); const server = require('./libs/server.js') const util = require('./libs/util.js'); const blinky = require('./libs/blinky.js'); const packageJSON = require('./package.json'); const INTERRUPTS = ['SIGINT', 'SIGTERM']; global.appName = packageJSON.name; global.appVersion = packageJSON.version; global.config = process.argv[2] || __dirname + '/config.json'; handleInterrupts(); util.fileExists(config) .then((result) => { global.config = require(result.path); global.config.path = result.path; }) .then(logger.initialize) .then(blinky.initialize) .then(() => { logger.info("launching " + packageJSON.name + " " + packageJSON.version); }) .then(api.setupEndpoints) .then(server.start) .catch((err) => { util.exit(err); }); function handleInterrupts() { for (var index = 0; index < INTERRUPTS.length; index++) { process.once(INTERRUPTS[index], async (code) => { await blinky.handleEvent('stopped'); util.exit(undefined, code); }); } }