-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
46 lines (39 loc) · 1.27 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { loggers } from 'winston';
import config from './config/config';
import app from './config/express';
/* eslint-disable no-unused-vars */
import db from './config/sequelize';
const cron = require("node-cron");
import migrateData from './server/helpers/migrateData'
const debug = require('debug')('amida-api-boilerplate:index');
/* eslint-enable no-unused-vars */
// Get default logger
const logger = loggers.get(config.loggerName); // eslint-disable-line no-global-assign
// make bluebird default Promise
Promise = require('bluebird'); // eslint-disable-line no-global-assign
cron.schedule("*/5 * * * *", () => {
console.log("running a task every 5 mins");
migrateData.getData();
});
// Synchronizing any model changes with database.
db.sequelize
.sync()
.then(() => {
logger.info('Database synchronized');
// module.parent check is required to support mocha watch
if (!module.parent) {
// listen on port config.port
app.listen(config.port, () => {
logger.info(`The application has started on port ${config.port} (${config.env})`, {
port: config.port,
node_env: config.env,
});
});
}
})
.catch((error) => {
if (error) {
logger.error('An error occured: ', error);
}
});
export default app;