Unable to set up local service

From :

https://docs.couchbase.com/nodejs-sdk/2.6/sample-app-backend.html

Applying this :

The statement is ready! You can execute this statement by wrapping it in a `couchbase.N1qlQuery.fromString()` . Here it is very simple, no placeholders and no particular tuning of the query is necessary, so the simple method will be used:

```
bucket.query(q, callbackFn)
```

The results of the query are returned in a list of records in the callback, which then is added to the response:

```
function(err, rows) {
    if (err) {
      res.status(500).send({
        error: err
      });
      return;
    }

    res.send({
      data: rows,
      context: [qs]
    });
  }
```
const express = require('express');
 const couchbase = require('couchbase');
const cluster = new couchbase.Cluster('couchbase://localhost/');
    cluster.authenticate('username', 'password');

const bucket = cluster.openBucket('bucketname', function(err) {
    if (err) {
        console.log('Bucket connection failed', err);
        return;
    }
        console.log('Connected to Couchbase!');
    });

const app = express();

    app.get('/',function(req,res){

        var qs;

        qs = "SELECT * FROM bucketname";

const q = couchbase.N1qlQuery.fromString(qs);
        bucket.query(q, function(err, teams) {
            if (err) {
                res.status(500).send({
                    error: err
                });
                return;
            }
            console.log("Got teams:  ", teams);
            res.json({
                data: teams
            });
        });
    });

    app.listen(3000, function () {
        console.log('App listening on port 3000!');
    });

Hi @Coucher,

Do you have a question, or are you trying to submit some feedback about the documentation?

Could not delete topic…

Related issue has been resolved

Thank you

1 Like