Running github/docs example

Hi,
I’m trying to run the Node SDK code from github for provisioning clusters. The code fails on the call to create bucket using bucket manager.

ERR: Error: cluster object was closed
at Connection.close (D:\workspace\cb\node_modules\couchbase\lib\connection.js:266:24)
at D:\workspace\cb\node_modules\couchbase\lib\cluster.js:612:14

Two questions:

  1. Why do we need “const bucket = cluster.bucket(“default”);” call?
  2. Can someone explain why this is happening and how can I fix this?

Thanks,
Kashyap

Hi , @gkashyap i see package.json refers to
“dependencies”: {
“couchbase”: “^3.0.2”
}

Can you try using the latest 3.1.1 and see if it helps ? There were some issues fixed in 3.1 .

Hi Arun,
I’m getting the same result. I’m running the example in command prompt with node command. This is just a test project for couchbase with javascript. If this works well I will consider integrating CB with this API. (My python code works fine and I’m able to create bucket. Node SDK code fails.)

Hi @AV25242 any other solution, suggestion?

Hello @gkashyap here is my code

var couchbase = require('couchbase')

let runSampleCode = async () => {
  var cluster = await couchbase.connect('couchbase://localhost', {
    username: 'Administrator',
    password: 'password',
  
  })
  const bucketMgr = cluster.buckets();
  await bucketMgr.createBucket({
    name: "testBucket",
    flushEnabled: false,
    replicaIndex: false,
    ramQuotaMB: 200,
    numReplicas: 1,
    bucketType: couchbase.BucketType.Couchbase,
  });

 }
runSampleCode()
  .then(() => {
    console.log("Exiting app...")
    process.exit(1);
  })
  .catch(e => {
    console.log(e);
    console.log("Exiting app...")
    process.exit(1);
  })

I tried creating hello and test bucket and it works fine for me.

my package.json setting

{
  "name": "myProject",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "couchbase": "^3.1.1"
  }
}

You are right you dont need
cluster.bucket('default')

Hello @gkashyap did this help any ?

Hi @AV25242 The code that you provided does indeed work but it is different from the code on github.
When I try to do it with the version I posted, I get bizarre errors. It even fails to recognize the cluster.buckets() function and the error reads that it is not a function.
I’m left wondering what’s so special about the code that you’ve written vs the code on github using ‘new’ [ const cluster = new couchbase.Cluster()].
https://docs.couchbase.com/sdk-api/couchbase-node-client/Cluster.html
The example shows it but when executing, it fails.
Can you shed some light on this?
Thanks.