Reputation: 81
I am successfully connecting my couchbase server with my application using localhost:3000
var express = require('express');
var bodyParser = require("body-parser");
var couchbase =require("couchbase");
var request = require("request");
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true}));
var cluster = new couchbase.Cluster('couchbase://localhost');
cluster.authenticate('Administrator', 'ABcd1234');
var bucket = cluster.openBucket('non-med'); //the name of bucket is 'example'
bucket.on('error', function(err) { console.log('Bucket: CONNECT ERROR:', err);});
module.exports.bucket = bucket;
var routes = require("./routes.js")(app);
var server = app.listen(3000, function(){
console.log("Listening on port%s...", server.address().port);
});
I have also downloaded Couchbase Sync Gateway from on my mac in commend line and service is loaded shown as follows
sudo ./sync_gateway_service_install.sh
chown: sync_gateway: illegal user name
chown: sync_gateway: illegal user name
/Library/LaunchDaemons/com.couchbase.mobile.sync_gateway.plist: service already loaded
Could everyone tell you how can i configure the Conuchbase Sync Gateway in detail??
Is there any new file needed to create e.g. sync-gateway-config.json? If so,
(2a)Where do i include this file? My application project folder?
(2b)May i know the format of json?
Thanks
Upvotes: 0
Views: 1334
Reputation: 2286
Sync Gateway talks directly to Couchbase Server. (In production you will usually not run them on the same machine. Make sure firewall/network filtering doesn't block access.)
Sync Gateway listens for connections from your client (mobile) applications. It does not interact with your Node app in most typical scenarios.
You configure Sync Gateway by supplying a file with your parameters. The name of the file is not important. The format and parameters are in the documentation here: https://developer.couchbase.com/documentation/mobile/current/guides/sync-gateway/config-properties/index.html
There are also sample configuration files included in the Sync Gateway distribution.
You do not need to create channels via the admin interface. You typically do this in the configuration file or via the sync function. It is very important to understand the sync function and what it does. See the documentation here: https://developer.couchbase.com/documentation/mobile/2.0/guides/sync-gateway/sync-function-api-guide/index.html
Upvotes: 1
Reputation: 203
Sync gateway needs to run as a separate file.You can set set syncing criteria by creating channels in http://localhost:4985/_admin/
. You can refer https://developer.couchbase.com/documentation/mobile/current/installation/sync-gateway/index.html to run the sync-gateway. I'll attach a sample sync-gateway configuration file below. Cheers!!
{
"log": [
"HTTP+"
],
"adminInterface": "localhost:4985", //Public port
"interface": "localhost:4984", //Admin port
"databases": {
"your_cluster_name": { //add your couchbase cluster name
"server": "http://localhost:8091", //add couchbase server url
"username": "your_username",
"password": "your_password",
"bucket": "your_bucket_name",
"users": {
"GUEST": {
"disabled": true
},
"admin": {
"admin_channels": ["*"], //give permission to all the channels
"password": "123456" //admin channel password
}
},
"import_docs": "continuous",
"enable_shared_bucket_access": true,
"sync":`
function(doc) {
channel(filter); // set your filtering criteria
}`
}
}
}
Upvotes: 2