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 packageJSON = require('./package.json'); const INTERRUPTS = ['SIGINT', 'SIGTERM']; 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(() => { logger.info("launching " + packageJSON.name + " " + packageJSON.version); }) .then(api.setupEndpoints) .then(server.start) .catch((err) => { logger.error(err); process.exit(1); }); function handleInterrupts() { for (var index = 0; index < INTERRUPTS.length; index++) { process.once(INTERRUPTS[index], (code) => { watchers.stop() .then(exit(code)) .catch(exit(code)); }); } }