-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb.js
More file actions
37 lines (28 loc) · 972 Bytes
/
web.js
File metadata and controls
37 lines (28 loc) · 972 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
36
37
var express = require('express');
var app = express.createServer(express.logger());
var mongo = require('mongoskin');
var mongodb = require('mongodb'); // just to get the ObjectID type, use the skin for everything else
var ObjectID = require('mongodb').ObjectID; // Get the objectID type
var conString = process.env.MONGOHQ_URL
var db = mongo.db(conString, {
auto_reconnect: true,
poolSize: 5,
safe: false
});
app.get('/', function(request, response) {
db.collection( 'currentForecast' ).find( request.query ).toArray( function( err, result )
{
if (err) { response.send(err) }
else { response.send(JSON.stringify(result)) }
})
});
var port = process.env.PORT || 5000;
app.listen(port, function() {
console.log("Listening on " + port);
});
process.on('SIGINT', function() {
console.log('Received SIGINT');
db.close(function(){
console.log('weatherparser server has closed its database');
});
});