-
Notifications
You must be signed in to change notification settings - Fork 18
/
server.js
39 lines (31 loc) · 982 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
'use strict';
var express = require('express');
var path = require('path');
var mongo = require('mongodb');
var routes = require('./app/routes/index.js');
var api = require('./app/api/url-shortener.js');
require('dotenv').config({
silent: true
});
var app = express();
mongo.MongoClient.connect(process.env.MONGOLAB_URI || 'mongodb://localhost:27017/url-shortener', function(err, db) {
if (err) {
throw new Error('Database failed to connect!');
} else {
console.log('Successfully connected to MongoDB on port 27017.');
}
// The format follows as, alias to use for real path, also allows permission to such path.
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
db.createCollection("sites", {
capped: true,
size: 5242880,
max: 5000
});
routes(app, db);
api(app, db);
var port = process.env.PORT || 8080;
app.listen(port, function() {
console.log('Node.js listening on port ' + port);
});
});