-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
46 lines (30 loc) · 1.05 KB
/
server.js
File metadata and controls
46 lines (30 loc) · 1.05 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import express from "express";
import mongoose from "mongoose";
import path from "path";
import { APP_PORT, DB_URL } from "./config";
import errorHandler from "./middlewares/errorHandler";
import routes from './routes';
const morgan = require('morgan');
const fs = require('fs');
const app = express();
mongoose.connect(DB_URL, { useNewUrlParser: true, useUnifiedTopology: false });
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'console error:'));
db.once('open', () => {
console.log("db connected")
})
// logging in file
// var accessLogStream = fs.createWriteStream(__dirname + '/access.log', { flags: 'a' })
// app.use(morgan('combined', { stream: accessLogStream }))
//logging in console
app.use(morgan('combined'));
global.appRoot = path.resolve(__dirname);
app.use(express.urlencoded({ extended: false }))
app.use(express.json());
app.use('/api/v1', routes);
app.use('/uploads', express.static('uploads'))
//error handling
app.use(errorHandler)
app.listen(APP_PORT, () =>
console.log(`listening on port ${APP_PORT}.`)
)