-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
47 lines (38 loc) · 1.41 KB
/
app.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
47
/* eslint-disable import/no-dynamic-require */
const express = require('express');
const bodyParser = require('body-parser');
const morgan = require('morgan');
// eslint-disable-next-line no-path-concat
// eslint-disable-next-line import/no-dynamic-require
// eslint-disable-next-line no-path-concat
const config = require(__dirname + '/config/app.json');
const db = require('./models');
const app = express();
const PORT = process.env.PORT || config.port || 8000;
// this lets us parse 'application/json' content in http requests
app.use(bodyParser.urlencoded({ extended: true }));
// add http request logging to help us debug and audit app use
const logFormat = process.env.NODE_ENV === 'production' ? 'combined' : 'dev';
app.use(morgan(logFormat));
// this mounts controllers/index.js at the route `/api`
app.get('/', (req, res) => {
res.send('Hello World, from express');
});
app.use('/', require('./controllers'));
db.sequelize.sync({ force: true, logging: false }).then(() => {
console.log('Database & tables created!');
const { exec } = require('child_process');
exec('npx sequelize-cli db:seed:all', (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
});
});
// start up the server
app.listen(PORT, () => console.log(`Listening on ${PORT}`));