Starting with Node.js and CouchDB without libraries like nano or cradle

Possible duplicate:
Getting bad_request invalid_json error when trying to insert a document into CouchDB from Node.js

Highest voice response on CouchDB and Node.js - Which module do you recommend? recommends not using libraries like nano or cradle starting with Node.js and CouchDB.

However, I did not find a tutorial on how to perform standard operations for all DBMSs, such as creating a database, creating a table, adding and viewing data, etc. programmatically.

EDIT: (partial answer) after installing and running CouchDB go to http://localhost:5984/_utils/script/couch.js.

+5
source share
4

CouchDB book.

, : , (, , , ), .

- .:) ..

CouchDB, . nano, API , - .

- , , , , :)

nano, :

+5

Ruben Verborgh - .

var http = require('http')
var sys = require('sys')


var couchdbPath = 'http://localhost:5984/'

request = require('request')
h = {accept: 'application/json', 'content-type': 'application/json'}
request(
  {uri: couchdbPath + '_all_dbs', headers:h}, 
  function(err, response, body) { console.log(sys.inspect(JSON.parse(body))); }
)

// add database
request(
  {uri: couchdbPath + 'dbname', method:'PUT', headers:h},
  function (err, response, body) {
    if (err)
      throw err;
    if (response.statusCode !== 201)
      throw new Error("Could not create database. " + body);
  }
)

// Modify existing document
var options = {
  host: "localhost",
  port: 5984,
  path: "/dbname",
  headers: {"content-type": "application/json"},
  method: "PUT"
};

var req = http.request(options, function(res) {
  console.log('STATUS: ' + res.statusCode);
  //console.log('HEADERS: ' + JSON.stringify(res.headers));
  res.setEncoding('utf8');
  res.on('data', function (chunk) {
    console.log('BODY: ' + chunk);
  });
});

req.on('error', function(e) {
  console.log('problem with request: ' + e.message);
});

// write data to request body
req.write(JSON.stringify({
  "_id":"rabbit",
  "_rev":"4-8cee219da7e61616b7ab22c3614b9526",
  "Subject":"I like Plankton"
}));

req.end();

:

+2

CouchDB SQL. "NoSQL".

, ..

.

REST API . , HTTP GET URL-: http://some.server/someDbName/_all_docs

" CouchDB" Google.

, . ( -, .)

http- node.js, request http . http.get, :

var http = require( 'http' );

http.get( 'http://some.url/with/params', function( res ) {
    // res has the values returned
});

:

-, , , . Node v0.8, 0.4.

-, request = require('request') ( ?). , .

-, GET-. - :

var http = require( 'http' );
http.get( 'http://localhost:5984/_all_dbs', function( res ) {
    console.log( res );
});

, . , , couchdb;)

, . , require('request'), , .

0

Here are some practical examples, thoughts, and code snippets to help with your research.

Simple blog with Coffeescript, Express and CoudbDB

Thoughts on developing using CouchDB and Nodejs

Bind CouchDB and Node.js

Getting started with Node.js, Express and CouchDB - this link is not available now, but it seems to be a temporary problem.

Here's one for testing CouchDB - Mock testing CouchDB using Node.js

Hope this helps.

0
source

All Articles