-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
executable file
·30 lines (24 loc) · 1.09 KB
/
app.js
File metadata and controls
executable file
·30 lines (24 loc) · 1.09 KB
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
const express = require('express');
const util = require('util');
const bodyParser = require('body-parser');
const { PORT, DB_USERNAME, DB_PASSWORD, DB_HOST, ...rest } = require('./config/env');
const database = require('./config/database');
const router = require('./src/routers');
const { watchCollection } = require('./src/watch/changeStream');
const cors = require('cors');
const {createLogger} = require('./src/logger/logger')
const {setLatestDocument} = require('./src/controller/DocumentStorage')
const logger = createLogger('app')
database.connect(DB_USERNAME, DB_PASSWORD, DB_HOST).then(() => {
const app = express();
watchCollection((change) => {
console.log(util.inspect(change, { depth: null }));
logger.info(util.inspect(change, { depth: null }));
console.log(util.inspect(change, { depth: null }));
setLatestDocument(change); // Update the stored document
});
app.use(cors());
app.use(bodyParser.json());
app.use('/', router);
app.listen(PORT, () => console.log(`example app listening on port ${PORT} ${rest.GREETING}`));
});