-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
29 lines (23 loc) · 735 Bytes
/
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
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const morgan = require('morgan');
const db = require('./db/db');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(morgan('dev'));
app.use(function(err, req, res, next) {
console.error(err.stack);
res.status(500).send('Something broke!');
});
if (require.main === module) {
//will only run when run with npm start and not with npm test to avoid db syncing in multiple threads when running tests
db.sync()
.then(() =>
app.listen(3000, function() {
console.log('Server is listening on port 3000!');
})
)
.catch(console.error);
}
module.exports = app;