totaljs / framework

Node.js framework
http://www.totaljs.com
Other
4.36k stars 450 forks source link

request timeout when using couchbase sdk #596

Closed Pourya8366 closed 6 years ago

Pourya8366 commented 6 years ago

I download the empty project and add the couchbase node.js sdk, then i want to add some data in a bucket in a route, but when i call that route, response would be request timeout!

this is the default controller, my question is how i can use couchbase properly in totaljs?

var couchbase = require("couchbase");
var cluster = new couchbase.Cluster("couchbase://localhost/");
cluster.authenticate("admin", "123456");
var bucket = cluster.openBucket("test");

exports.install = function() {
  F.route("/", view_index);
  // or
  // F.route('/');
};

function view_index() {
  var self = this;
  console.log("here");
  bucket.insert(
    "roles",
    {
      test: 1234
    },
    function(err, result) {
      if (err) {
        console.log("err: " + err);
        self.json({ status: 400 });
      } else {
        console.log("success1");
        self.json({ status: 200 });
      }
    }
  );
}
molda commented 6 years ago

Hi @Pourya8366 have you tried to run the couchbase code separately without framework? Does the cluster even connect to the server?

petersirka commented 6 years ago

Hi @Pourya8366, what is the output from console?

Pourya8366 commented 6 years ago

Problem solved! i just have to add the couchbase port which is 8091 in default to the cluster argument for finding it!

var cluster = new couchbase.Cluster("couchbase://localhost:8091/");

and when i check in more, i find out the insert execute after many seconds and the output will be success1 because it takes long for couch to find the cluster without port explicitly written!