Unable to connect to the sync gateway on backend using Node.js


#1

node.js script fails to do anything aka (Swagger fails to connect?). Note that this is my first time setting up a node.js backend server to connect with my couchbase server database (via the sync gateway). I have followed some online tutorials and read up a bit. Even though my js script appears to run without any errors and it is syntactically correct, it runs through the .js file, prints the following console.logs, and then just stops. I cannot find any process running (ps -e) or anything for it.

“MADE IT HERE!”
“END of file”

What I would have expected is that 1) some background swagger process for monitoring changes from the two channels listed in the code below would be running, and 2) when the sync gateway changes for those channels, my other console.logs would print. Instead, nothing happens.

Can anyone see from my .config and node.js script what is going wrong. Greatly appreciated. Thank you. Two things to note… 1) Yes, my database is named “sync_gateway”, I’ll choose a better name later. 2) I was only able to find the sync-gateway-spec in yaml, so I converted it to .json via an online converter.

Here is my js script that runs on node.js.

const swagger = require('swagger-client');
const spec = require('./sync-gateway-spec.json');

const SYNC_GATEWAY_HOST = 'http://<username>:<password>@localhost:4984';
spec.host = SYNC_GATEWAY_HOST;

let query = {
  db: 'sync_gateway',
  filter: 'sync_gateway/bychannel',
  channels: ['new_msg_notification', 'userchannels'],
  active_only: true,
  include_docs: true,
  feed: 'longpoll',
  timeout: 0
};

console.log("MADE IT HERE!");

// Setup to use swagger syncronously
let client = new swagger({
  //url: 'http://developer.couchbase.com/mobile/swagger/sync-gateway-public/spec.json',
  spec: spec,
  success: function() {
    monitor(client);
  },
  function(error) {
    console.log('client error: ', error.statusText);
    process.exit(1);
  }
});

function monitor(client) 
{
  console.log("MADE IT TO MONITOR");
  client.database.get_db_changes(query, message);
}

function message(response) 
{
  console.log("MADE IT TO MESSAGE");
  console.log(response.data);
  query.since = response.obj.last_seq;
  monitor(client);
}

console.log("END of file");

And here is my sync_gateway_config.json

   "interface":":4984",
   "adminInterface":":4985",
   "log":["*"],
   "CORS": {
		"Origin": ["http://localhost:8091"],
		"LoginOrigin": ["http://localhost:8091"],
		"Headers": ["Content-Type","authorization"],
		"MaxAge": 17280000
	},
   "databases":{
      "sync_gateway":{
         "users": {
				"<username>": {"password": "<password>", "admin_roles": ["admin"]}
			},
			"roles": {
				"user": {},
				"admin": {}
			  },
         "server":"http://localhost:8091",
         "enable_shared_bucket_access": true,
         "enable_extended_attributes": true,
         "bucket":"sync_gateway",
         "username":"my_username",
         "password":"my_password",
         "sync":`
            function (doc, oldDoc) 
            { ...