Created
November 16, 2011 08:58
-
-
Save dbrain/1369624 to your computer and use it in GitHub Desktop.
Node v0.6.1 EADDRINUSE
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'); | |
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