-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
30 lines (25 loc) · 967 Bytes
/
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
const express = require('express')
const app = express();
var ejs = require('ejs')
var path = require('path')
var mongoose = require('mongoose')
const bodyParser = require('body-parser');
var config = require('./config.js')
var options = { useNewUrlParser: true }
var constring = config.db.protocol+"://"+config.db.username+":"+config.db.password+"@"+config.db.host+":"+config.db.port+"/"+config.db.database;
console.log(constring)
mongoose.connect(constring,options)
mongoose.connection.on('connected', () => {
console.log('mongoose connection open to' );
});
mongoose.connection.on('error', (err) => {
console.log(`mongoose connection err: `, err);
});
app.set('view engine','ejs')
app.use( express.static( "public" ) );
app.use(bodyParser.urlencoded({ extended: false }));
const db = require('./dbconfig.js')
require('./routes.js')(app,db);
app.listen(process.env.PORT || 2018, function () {
console.log('server is started')
})