Error Connecting to CouchBase from Node.js using C

2019-02-19 15:58发布

问题:

Using https://github.com/couchbase/couchnode @v.1.2.4

Attempting to connect to CouchBase server using the code in the README

var couchbase = require('couchbase');
var cluster = new couchbase.Cluster();
var db = cluster.openBucket('default');

db.set('testdoc', {name:'Frank'}, function(err, result) {
  if (err) throw err;

  db.get('testdoc', function(err, result) {
    if (err) throw err;

    console.log(result.value);
    // {name: Frank}
  });
});

but am getting the following error:

db.js:2
var cluster = new couchbase.Cluster();
              ^
TypeError: undefined is not a function
    at Object.<anonymous> (/Users/n/code/time/test/db.js:2:15)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3
npr:time n$ 

Additional details:

  • Running Couchbase Version 2.5.1 on Mac (server appears to be working fine)
  • Node Version 0.10.29 (latest)

Note: We tried searching on the CouchBase Bug Tracker: http://www.couchbase.com/issues/issues/?jql=text%20~%20%22typeError%22 in case other people were having the same error. No luck.

回答1:

The "solution" was to use the "Developer Preview" of Couchbase

npm install couchbase@2.0.0-dp1

Then all the examples on https://github.com/couchbase/couchnode worked as expected.

See: http://blog.couchbase.com/nodejs-sdk-200-developer-preview