-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
31 lines (25 loc) · 719 Bytes
/
app.js
File metadata and controls
31 lines (25 loc) · 719 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
var express = require('express')
var busboy = require('express-busboy')
var routes = require('./routes')
var mongodb = require('mongodb')
var app = express()
var dbUrl = process.env.MONGODB_URI
var db
mongodb.MongoClient.connect(dbUrl, function (err, database) {
if (err) throw err
db = database
})
// middleware for parsing multipart (file) uploads
busboy.extend(app, {
upload: true
})
// custom middleware to expose the db connection pool to every request
app.use(function(request, response, next) {
request.db = db
next()
})
app.use(express.static(__dirname + '/public'))
app.use('/', routes)
app.listen(process.env.PORT || 5000, function() {
console.log("Server running on localhost...")
})