-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathserver.js
43 lines (29 loc) · 903 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
36
37
38
39
40
41
42
43
var express = require('express');
var mongoose = require('mongoose');
var authormodel = require('./models/author.js');
var app = express();
app.set('views', __dirname);
app.set('view engine', 'jade');
app.use(express.static(__dirname));
app.get('/api/authors', function(req, res) {
mongoose.model('Author').find({}).exec(function(error, collection) {
res.send(collection);
})
})
app.get('*', function(req,res){
res.render('index');
});
//mongoose.connect('mongodb://localhost/codebabeldashboard');
mongoose.connect('mongodb://userdev1:[email protected]:53394/codebabeldashboard');
var con = mongoose.connection;
con.once('open', function() {
console.log('connected to mongodb successfully!!!')
authormodel.seedAuthors();
console.log('updated the database')
});
let port = process.env.PORT;
if (port == null || port == "") {
port = 8000;
}
app.listen(port);
//app.listen(3000);