-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
29 lines (22 loc) · 812 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
const express = require('express');
const mongoose = require('mongoose');
const requireDir = require('require-dir');
const bodyParser = require('body-parser');
const methodOverride = require('method-override');
// start app
const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json())
app.set('view engine', 'ejs');
app.set('views', './src/views');
app.use(express.static('public'));
app.use(methodOverride('_method'));
//start DB
mongoose.connect('mongodb://localhost:27017/booksapp', { useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false });
// import all models
requireDir('./src/models');
// set routes for /app
app.use('/app', require('./src/routes/routes'));
app.listen(3000, () => {
console.log('server running on port 3000');
});