-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
31 lines (24 loc) · 852 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
var express = require("express");
var jade = require("jade");
var mongoose = require("mongoose");
var Vocabulary = require("./modules/vocabulary.js")
var mongo_uri = process.env.MONGOLAB_URI || "mongodb://localhost:27017/test"
var port = process.env.PORT || 3000;
var app = express.createServer(express.logger());
app.use(express.static(__dirname + "/assets"));
app.listen(port, function() {
console.log("Listening on ..." + port);
mongoose.connect(mongo_uri, function(err) {
if (err) throw err;
});
mongoose.connection.on("open", function(err){
if (err) throw err;
console.log("Mongoose is connected!");
});
});
app.get('/', function(request, response) {
var vocabulary = Vocabulary(mongoose);
vocabulary.get_random(function(result) {
response.render("index.jade", {german: result.german, english: result.english});
});
});