const watchers = require('./libs/watchers.js'); const logger = require('./libs/logger.js'); const packageJSON = require('./package.json'); const INTERRUPTS = ['SIGINT', 'SIGTERM']; logger.info(packageJSON.name + ' ' + packageJSON.version + ' starting...'); handleInterrupts(); watchers.initialize() .then(watchers.start) .catch((err) => { logger.error(err); exit(1); }); function exit(code) { code = code || 0; logger.info(packageJSON.name + ' ' + packageJSON.version + ' exiting with code \'' + code + '\'...'); process.exit(code); } function handleInterrupts() { for (var index = 0; index < INTERRUPTS.length; index++) { process.once(INTERRUPTS[index], (code) => { watchers.stop() .then(exit(code)) .catch(exit(code)); }); } }