-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
35 lines (27 loc) · 871 Bytes
/
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
//import modules
const express = require('express')
const mongoose = require('mongoose');
const morgan = require('morgan')
require('dotenv').config()
const app = express();
const port = 4000;
app.use(morgan('dev'));
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
//create connection
mongoose.connect(process.env.URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true
})
//get default connection
let db = mongoose.connection;
//handles error and connections
db.on('err', console.error.bind(console, 'connection error: '))
db.once('open', () => console.log('connected to mongod database'))
//requires routes
const apiRoutes = require('./routes/apiRoutes.js')
app.use('/api', apiRoutes)
app.listen(port, console.log(`Server listening on port:${port}`))
module.exports = app;