Skip to content

Instantly share code, notes, and snippets.

@dbrain
Created November 16, 2011 08:58
Show Gist options
  • Save dbrain/1369624 to your computer and use it in GitHub Desktop.
Save dbrain/1369624 to your computer and use it in GitHub Desktop.
Node v0.6.1 EADDRINUSE
var http = require('http');
var httpOptions = {
hostname: 'localhost',
port: '5984',
path: '/native_view_test',
auth: 'dbrain:password',
method: 'POST',
headers: { 'Content-Type': 'application/json' },
agent: false
};
var numberOfDocs = 100000;
var docsWritten = 0;
var dataCreated = 0;
function createData() {
dataCreated++;
var req = http.request(httpOptions, function gotResponse(response) {
response.on('end', function documentCreated() {
docsWritten++;
if (docsWritten === numberOfDocs) {
allDocumentsCreated();
} else {
createData();
}
});
});
req.on('error', function (err) {
console.log(err);
});
var doc = { name: 'You died of dysentary ' + dataCreated + ' times :(' };
req.end(JSON.stringify(doc));
}
function allDocumentsCreated() {
console.log("DONE");
}
createData();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment