-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
48 lines (38 loc) · 1.15 KB
/
app.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
const express = require('express')
var mongoose = require('mongoose')
var path = require('path')
var bodyParser = require('body-parser')
//DB init
mongoose.connect('mongodb://localhost:27017/tf', { useNewUrlParser: true })
var db = mongoose.connection
//DB callbacks
db.once('open', function() {
console.log('Connected to MongoDB...')
})
db.on('error', function(err) {
console.log(err)
})
//Import routes
var indexRouter = require('./routes/index');
var homeRouter = require('./routes/home');
//Express init
const app = express()
//Express view init to EJS
app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'ejs')
//Express public folder init
app.use(express.static(path.join(__dirname, 'public')))
//Parsing sets
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
app.get('/', function(req, res, next) {
console.log(req.headers["user-agent"])
next()
})
//Express root routing
app.use('/', indexRouter)
app.use('/home', homeRouter)
//Server listen init
app.listen(3000, function() {
console.log('Server listening on port 3000...')
})