-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdeep.js
More file actions
42 lines (34 loc) · 1020 Bytes
/
deep.js
File metadata and controls
42 lines (34 loc) · 1020 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
38
39
40
41
42
var connect = require( 'connect' );
var mongo = require( 'mongodb' );
var port = process.env.PORT || 3000;
var mongoUri = process.env.MONGOLAB_URI;
var contactsCollection = null;
var contacts = {
add: function( firstName, lastName, requestCallback )
{
if ( contactsCollection != null )
{
contactsCollection.insert( { "firstName": firstName, "lastName": lastName }, function(error, result)
{
requestCallback( null, "success" );
});
}
}
};
connect.createServer(
require( 'connect-jsonrpc' )( contacts )
).listen( port );
mongo.connect( mongoUri, {}, function ( error, db )
{
db.addListener( "error", function handleError( error )
{
console.log( "Error connecting to MongoLab" );
});
db.createCollection( "contacts", function ( error, collection )
{
db.collection( "contacts", function ( error, collection )
{
contactsCollection = collection;
});
});
});