Earlier this was the code to create a database using Node.js:
var client = http.createClient(5984, "127.0.0.1")
var request = client.request("PUT", "/johnTest");
request.end();
request.on("response", function(response) {
response.on("end", function() {
if ( response.statusCode == 201 ) {
console.log("Database successfully created.");
} else {
console.log("Could not create database.");
}
});
});
Now since createClient has been deprecated, how do we create a DB using Node.js
var client = http.createClient(5984 /* port */, "127.0.0.1" /* host */)
var request = client.request("PUT" /* method */, "/johnTest" /* path */);
would be converted to:
var request = http.request({
port: 5984,
host: '127.0.0.1',
method: 'PUT',
path: '/johnTest'
});
Also, note, the way you are waiting for the response 'end'
event will work in node v0.8.x
, but will not fire in v0.10.x
. I assume since you posted this code that is does actually work though, so you are on v0.8.x
. If that is not the case, let me know.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With