Created
October 21, 2011 13:53
-
-
Save treffynnon/1303904 to your computer and use it in GitHub Desktop.
Connect to an IrisCouch database from Node.js, save a new document and retrieve it back again.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
http.createServer(function (req, http_res) { | |
http_res.writeHead(200, {'Content-Type': 'text/plain'}); | |
var response = ''; | |
var cradle = require('cradle'); | |
var connection = new(cradle.Connection)('https://subdomain.iriscouch.com', 443, { | |
auth: { username: 'username', password: 'password' } | |
}); | |
var db = connection.database('database_name'); | |
db.save('document_key', { | |
name: 'A Funny Name' | |
}, function (err, res) { | |
if (err) { | |
// Handle error | |
response += ' SAVE ERROR: Could not save record!!\n'; | |
} else { | |
// Handle success | |
response += ' SUCESSFUL SAVE\n'; | |
} | |
db.get('document_key', function (err, doc) { | |
response += ' DOCUMENT: ' + doc + '\n'; | |
http_res.end(response); | |
}); | |
}); | |
}).listen(8071); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment