Apache CouchDB™ is a database that uses JSON for documents, JavaScript for MapReduce queries, and regular HTTP for an API. It is a NoSQL database. It is not a relational database.
Node example to get database names using GET method:
var http = require('http');
http.createServer( function( req, res ){
var options = {
host: 'localhost',
port: '5984',
method: 'GET',
path: '/_all_dbs'
}
//make a http request to database
var request = http.request( options, function(response){
var responseBody = "";
//receiving data
response.on("data", function( chunk ){
responseBody +=chunk;
});
//display function
response.on( "end", function(chunk){
res.writeHead( 200, { 'Content-Type':'text/plain' });
res.write( responseBody);
res.end();
});
//handling error
request.on('error', function(e){
console.log( 'problem with request: ' + e.message );
});
});
request.end();
}).listen(9000);
Create database using PUT method:
var http = require( 'http');
var options = {
host: 'localhost',
port: '5984',
method: 'PUT',
path: '/dbname'
}
//make a database request
var req = http.request( options, function(response){
response.on( "end", function(){
if( response.statusCode == 201){
console.log("Database successfully created.");
}else{
console.log( "Could not createdatabase." );
}
});
});
//handling error
req.on('error', function(e){
console.log( 'problem with request: ' + e.message );
});
There are modules for working with couchdb:
npm install felix-couchdb