-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmongo.app.js
More file actions
35 lines (28 loc) · 997 Bytes
/
mongo.app.js
File metadata and controls
35 lines (28 loc) · 997 Bytes
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
// [LOAD PACKAGES]
var http = require('http');
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
// [CONFIGURE APP TO USE bodyParser]
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// [CONFIGURE SERVER PORT]
var port = process.env.PORT || 54000;
// DEFINE MODEL
var Book = require('./db.mongo.example/models/book');
// [CONFIGURE ROUTER]
var router = require('./db.mongo.example')(app, Book);
// [RUN SERVER]
var server = app.listen(port, function(){
console.log("Express server has started on port " + port);
});
// CONNECT TO MONGODB SERVER
var db = mongoose.connection;
db.on('error', console.error);
db.once('open', function(){
// CONNECTED TO MONGODB SERVER
console.log("Connected to mongod server");
});
mongoose.connect('mongodb://localhost/mongodb_tutorial');
// mongoose.connect('mongodb://username:password@host:port/database?options...');