-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
48 lines (41 loc) · 1.17 KB
/
server.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
48
// REQUIRED DEPENDENCIES
const express = require('express');
const mongoose = require('mongoose');
const morgan = require('morgan');
const path = require('path');
const rfs = require('rotating-file-stream');
require('dotenv').config();
// App + PORT + Database URL
const app = express();
const PORT = process.env.PORT || 3000;
const CONNECTION_URI = process.env.MONGODB_URI || process.env.DB_URI;
// Middleware + Routes
// DEV (TEST)
app.use(
morgan('dev', {
skip: function (req, res) {
return res.statusCode < 400;
},
})
);
// create a rotating write stream
var accessLogStream = rfs.createStream('access.log', {
size: '10M', // rotate every 10 MegaBytes written
interval: '1d', // rotate daily
path: path.join('log'),
});
// setup the logger
app.use(morgan('combined', { stream: accessLogStream }));
const covidRoutes = require('./routes/data-routes');
app.use(covidRoutes);
// Connect to MongoDB -- Local Database
mongoose.connect(
CONNECTION_URI,
{
useNewUrlParser: true,
useUnifiedTopology: true,
},
() => console.log('DB connection successful!')
);
// Listen to the server
app.listen(PORT, () => console.log(`Listening...http://localhost:${PORT}`));