{"id":2494,"date":"2017-01-19T21:43:59","date_gmt":"2017-01-19T21:43:58","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=2494"},"modified":"2025-10-09T07:23:21","modified_gmt":"2025-10-09T14:23:21","slug":"node-js-swagger-monitor-document-changes-couchbase-mobile","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/","title":{"rendered":"Using Node.js and Swagger to Monitor Document Changes in Couchbase Mobile"},"content":{"rendered":"<div style=\"overflow: auto\">\n<div style=\"float: left;width: 50%\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-392\" src=\"\/wp-content\/original-assets\/january-2017\/using-node.js-and-swagger-to-monitor-document-changes-in-couchbase-mobile\/node.js_logo.svg_.png\" alt=\"Node.js logo\" width=\"360\" height=\"220\" \/><\/div>\n<div style=\"float: left;width: 50%\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-408 alignnone\" src=\"\/wp-content\/original-assets\/january-2017\/using-node.js-and-swagger-to-monitor-document-changes-in-couchbase-mobile\/swagger-logo.png\" alt=\"Swagger Logo\" width=\"360\" height=\"360\" \/><\/div>\n<\/div>\n<p>When building applications with <a href=\"https:\/\/www.couchbase.com\/developers\/mobile\/\" target=\"_blank\" rel=\"noopener noreferrer\">Couchbase Mobile<\/a> there are a lot of interesting possibilities for server-side integration.<br \/>\nCreating business logic to resolve synchronization conflicts is one common use. The <a href=\"https:\/\/developer.couchbase.com\/documentation\/mobile\/current\/guides\/sync-gateway\/index.html?utm_source=blogs&amp;utm_medium=link&amp;utm_campaign=blogs\" target=\"_blank\" rel=\"noopener noreferrer\">Sync Gateway<\/a> document \u201cchanges\u201d feed makes all sorts of event-driven operations easy to implement, too. I\u2019ll explore this in upcoming posts.<\/p>\n<p>An app can use both <a href=\"https:\/\/developer.couchbase.com\/documentation\/mobile\/current\/guides\/sync-gateway\/index.html?utm_source=blogs&amp;utm_medium=link&amp;utm_campaign=blogs\" target=\"_blank\" rel=\"noopener noreferrer\">Sync Gateway<\/a> and <a href=\"https:\/\/developer.couchbase.com\/documentation\/mobile\/current\/guides\/couchbase-lite\/index.html?utm_source=blogs&amp;utm_medium=link&amp;utm_campaign=blogs\" target=\"_blank\" rel=\"noopener noreferrer\">Couchbase Lite<\/a> by directly calling the ReST API for each. That requires writing a bunch of boilerplate code that isn\u2019t much fun, though. PouchDB offers a compatible JavaScript option, but now there\u2019s a lighter-weight alternative.<\/p>\n<p>Not too long ago Couchbase switched to using Swagger to document the <a href=\"https:\/\/www.couchbase.com\/developers\/mobile\/?utm_source=blogs&amp;utm_medium=link&amp;utm_campaign=blogs\" target=\"_blank\" rel=\"noopener noreferrer\">Couchbase Mobile<\/a> APIs. Swagger does far more than create<br \/>\ndocumentation, though. With a single Swagger spec, you can generate documentation, server stub code, test cases, a sandbox site, and more. Best of all for me, Swagger can generate client SDKs\u2026 in 40 different languages!<\/p>\n<p>In this post, I\u2019m going to show how to use the Swagger Node.js client. We\u2019ll build a super simple app that monitors changes in documents in Couchbase. This will become the basis for building some other cool stuff coming up. Let\u2019s dive in.<\/p>\n<h2 id=\"what-we-ll-need\">What we\u2019ll need<\/h2>\n<p>To follow along, you\u2019ll want<\/p>\n<ul>\n<li>Node.js (I\u2019m using v6.9.1 on a Mac)<\/li>\n<li>Swagger JS (The Swagger Node.js client)<\/li>\n<li>Couchbase Sync Gateway<\/li>\n<li>The Sync Gateway Swagger spec<\/li>\n<\/ul>\n<p>I\u2019m assuming you already have Node.js installed.<\/p>\n<h2 id=\"install-the-swagger-js-library\">Install the Swagger JS Library<\/h2>\n<p>From a command line shell, change to the directory where you will keep your project.<\/p>\n<p>To get the Swagger client and dependencies, run<\/p>\n<pre><code class=\"language-bash\">$ npm install swagger-client<\/code><\/pre>\n<p>(You will see some warnings, which you can ignore.)<\/p>\n<h2 id=\"install-sync-gateway\">Install Sync Gateway<\/h2>\n<p>Download the Sync Gateway package for your platform <a href=\"https:\/\/www.couchbase.com\/nosql-databases\/downloads#cb-mobile\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>. (If your are running Linux and don\u2019t see a package for your distribution, see the instructions in<br \/>\n<a href=\"https:\/\/www.couchbase.com\/blog\/installing-sync-gateway-alternate-linux-distributions\/?utm_source=blogs&amp;utm_medium=link&amp;utm_campaign=blogs\" target=\"_blank\" rel=\"noopener noreferrer\">this blog post<\/a> for help.)<\/p>\n<p>In order to run Sync Gateway, we need to create a configuration file. Here\u2019s a simple setup we can use. Copy the text here and paste it into a file called \u201csync-gateway-config.json\u201d, or something similar.<\/p>\n<pre><code class=\"language-json\">{\r\n  \"log\": [\"HTTP+\"],\r\n  \"adminInterface\": \"127.0.0.1:4985\",\r\n  \"interface\": \"127.0.0.1:4984\",\r\n  \"CORS\": {\r\n    \"origin\":[\"*\"],\r\n    \"loginorigin\":[\"*\"],\r\n    \"headers\":[\"Content-Type\"],\r\n    \"maxAge\": 1728000\r\n  },\r\n  \"databases\": {\r\n    \"test\": {\r\n      \"server\": \"walrus:\",\r\n      \"users\": { \"GUEST\": {\"disabled\": false, \"admin_channels\": [\"*\"] } }\r\n    }\r\n  }\r\n}<\/code><\/pre>\n<p>This configuration uses a built-in database made for testing Sync Gateway. The server will only respond to connections on localhost, too. You can find resources to learn more about configuring Sync Gateway at the end of this post.<\/p>\n<p>Start Sync Gateway by running<\/p>\n<pre><code class=\"language-bash\">$ \/path\/to\/sync_gateway sync-gateway-config.json<\/code><\/pre>\n<p>You\u2019ll see some logging output. You might find it interesting to watch the logs when running the app later.<\/p>\n<h2 id=\"make-a-copy-of-the-sync-gateway-swagger-spec\">Make a copy of the Sync Gateway Swagger spec<\/h2>\n<p>You can find the Swagger spec for the public Sync Gateway ReST APi (versus the admin API) at <a href=\"https:\/\/docs.couchbase.com\/sync-gateway\/current\/_attachments\/sync-gateway-admin.yaml\">https:\/\/docs.couchbase.com\/sync-gateway\/current\/_attachments\/sync-gateway-admin.yaml<\/a>.<\/p>\n<p>Swagger specs are stored as JSON. Although Swagger can download the text directly, it\u2019s best to make a copy. That way if the spec changes it won\u2019t break your app.<\/p>\n<p>Copy the information into a file in your projet directory called sync-gateway-spec.json, or something similar. The file needs a .json extension for Node to process it.<\/p>\n<h2 id=\"create-the-node-js-app\">Create the Node.js app<\/h2>\n<p>Let\u2019s put the app together. Open up a new file in your project directory that ends with a .js extension. I used a file named app.js.<\/p>\n<pre><code class=\"language-JavaScript\">const Swagger = require('swagger-client');\r\nconst spec = require('.\/sync-gateway-spec.json');<\/code><\/pre>\n<p>The first line imports the Swagger client and makes it available. The second line is a bit more unusual. It initializes the <code>spec<\/code> object from the JSON in the file. This is why the .json extension is important. It\u2019s how Node recognizes we\u2019re<br \/>\nimporting JSON, not a regular package.<\/p>\n<p>The spec file has a host hardwired in, but let\u2019s go ahead and set it ourselves.<\/p>\n<pre><code class=\"language-JavaScript\">const SYNC_GATEWAY_HOST = 'localhost:4984';\r\n\r\nspec.host = SYNC_GATEWAY_HOST;\r\n<\/code><\/pre>\n<p>Next, we\u2019ll prepare the parameters for our call to the <code>_changes<\/code> endpoint.<\/p>\n<pre><code class=\"language-JavaScript\">let query = {\r\n  db: 'test',\r\n  filter: 'sync_gateway\/bychannel',\r\n  channels: 'notification',\r\n  active_only: true,\r\n  include_docs: true,\r\n  feed: 'longpoll',\r\n  timeout: 0\r\n};<\/code><\/pre>\n<p>Notice we have a mix here of the database name (test), which ends up being part of the endpoint URL, and some options we want to set.<\/p>\n<p>Now that we\u2019ve initialized what we need, we can create the Swagger client instance.<\/p>\n<pre><code class=\"language-JavaScript\">let client = new Swagger({\r\n  spec: spec,\r\n  success: function() {\r\n    monitor(client);\r\n  },\r\n  function(error) {\r\n    console.log('client error: ', error.statusText);\r\n    process.exit(1);\r\n  }\r\n});<\/code><\/pre>\n<p>There are several important things to note here.<\/p>\n<p>We\u2019re using the client syncronously. If you want, you can use JavaScript Promises by specifying <code>usePromise: true<\/code>. I didn\u2019t want to do that since I\u2019m not doing any real processing and it complicates the code a bit.<\/p>\n<p>Instead of <code>spec: spec<\/code>, we could have listed a url for the Swagger specification using <code>url:<\/code>. Again, you should avoid this, at least in production, because the spec could change remotely and break your code.<\/p>\n<p>The <code>success:<\/code> entry specifies two functions. Both are callbacks. The first is called if construction succeeds, the second if it fails. These are \u201cglobal\u201d, in a sense. These functions act as defaults if we don\u2019t specify different ones to the<br \/>\nindividual calls. That\u2019s really handy in the error case.<\/p>\n<p>We assign the instance to a variable <code>client<\/code>. The client instance is filled out asynchronously. It isn\u2019t ready to use until the success callback happens. So we have the interesting construct that <code>client<\/code> is used internally in the<br \/>\ncallback. In the Promises version, client would be passed as the argument in the <code>.then<\/code> clause.<\/p>\n<p>In the next part of the code, we use the client to listen to the <code>_changes<\/code> endpoint.<\/p>\n<pre><code class=\"language-JavaScript\">function monitor(client) {\r\n  client.database.get_db_changes(query, message);\r\n}<\/code><\/pre>\n<p>This presents a problem: how do we find out the name of the function we want to call? There\u2019s no fixed mapping between endpoints and functions names. This is another handy feature of Swagger. The client class is self-documenting. You call <code>help()<\/code> at whatever level you need. For example, to find out about endpoints under database, add this in your code:<\/p>\n<pre><code class=\"language-JavaScript\">client.database.help();<\/code><\/pre>\n<p>The help output shows up in the command line output (or your IDE\u2019s console). It will describe the endpoints and all the possible parameters.<\/p>\n<p>Going back to the client call, we see that we passed both the database name (required), and several parameters in lumped together in the <code>query<\/code> object. This was a little confusing. You might expect these to be separated out, but that won\u2019t<br \/>\nwork. None of the examples I found explained this.<\/p>\n<p>We supplied a callback function <code>message<\/code>. (Notice that\u2019s used if the ReST call succeeds. We rely on the default to handle failures.)<\/p>\n<pre><code class=\"language-JavaScript\">function message(response) {\r\n  console.log(response.data);\r\n  query.since = response.obj.last_seq;\r\n  monitor(client);\r\n}<\/code><\/pre>\n<p>The callback receives an object containing all the details of the response. I just wrote this app to show the loop structure needed to listen to the Sync Gateway changes feed. Hence, the <code>message<\/code> function doesn\u2019t do much. We write the call<br \/>\nresponse out for debugging purposes. We then want to go back and listen for the next update. Sync Gateway knows what to push based on sequence IDs. To control that, we use the <code>last_seq<\/code> information from our last response.<\/p>\n<p>That\u2019s it. Here\u2019s the complete code for the app.<\/p>\n<pre><code class=\"language-JavaScript\">const Swagger = require('swagger-client');\r\nconst spec = require('.\/sync-gateway-spec.json');\r\n\r\nconst SYNC_GATEWAY_HOST = 'localhost:4984';\r\n\r\nspec.host = SYNC_GATEWAY_HOST;\r\n\r\nlet query = {\r\n  db: 'test',\r\n  filter: 'sync_gateway\/bychannel',\r\n  channels: 'notification',\r\n  active_only: true,\r\n  include_docs: true,\r\n  feed: 'longpoll',\r\n  timeout: 0\r\n};\r\n\r\nlet client = new Swagger({\r\n  spec: spec,\r\n  success: function() {\r\n    monitor(client);\r\n  },\r\n  function(error) {\r\n    console.log('client error: ', error.statusText);\r\n    process.exit(1);\r\n  }\r\n});\r\n\r\nfunction monitor(client) {\r\n  client.database.get_db_changes(query, message);\r\n}\r\n\r\nfunction message(response) {\r\n  console.log(response.data);\r\n  query.since = response.obj.last_seq;\r\n  monitor(client);\r\n}<\/code><\/pre>\n<h2 id=\"final-notes\">Final notes<\/h2>\n<p>You can fire up your app and try it out. Make sure Sync Gateway is running. Then run<\/p>\n<pre><code class=\"language-bash\">$ node app.js<\/code><\/pre>\n<p>You should see a response in the Sync Gateway logs and something like this output by the app itself:<\/p>\n<pre><code class=\"language-JSON\">{\"results\":[\r\n{\"seq\":1,\"id\":\"_user\/GUEST\",\"changes\":[]}\r\n],\r\n\"last_seq\":\"1\"}<\/code><\/pre>\n<p>Now, add a new document. You can do this with cURL on the command line. Here\u2019s an example.<\/p>\n<pre><code class=\"language-bash\">$ curl -X PUT -H \"Content-Type: application\/json\" -d '{ \"key\": \"value\", \"channels\": \"notification\" }' https:\/\/localhost:4984\/test\/doc<\/code><\/pre>\n<p>Your Node app should output something like this:<\/p>\n<pre><code class=\"language-JSON\">{\"results\":[\r\n{\"seq\":2,\"id\":\"doc\",\"doc\":{\"_id\":\"doc\",\"_rev\":\"1-d0efa985de274451fc7cdcf471152ce2\",\"channels\":\"notification\",\"key\":\"value\"},\"changes\":[{\"rev\":\"1-d0efa985de274451fc7cdcf471152ce2\"}]}\r\n],\r\n\"last_seq\":\"2\"}<\/code><\/pre>\n<h3 id=\"other-resources\">Other Resources<\/h3>\n<p>Read more about <a href=\"https:\/\/www.couchbase.com\/products\/mobile\/\">Couchbase Mobile<\/a>.<\/p>\n<p>Read about the <a href=\"https:\/\/developer.couchbase.com\/documentation\/mobile\/current\/guides\/sync-gateway\/index.html?utm_source=blogs&amp;utm_medium=link&amp;utm_campaign=blogs\" target=\"_blank\" rel=\"noopener noreferrer\">Sync Gateway<\/a> <a href=\"https:\/\/developer.couchbase.com\/documentation\/mobile\/current\/references\/sync-gateway\/rest-api\/index.html?utm_source=blogs&amp;utm_medium=link&amp;utm_campaign=blogs\" target=\"_blank\" rel=\"noopener noreferrer\">ReST APIs<\/a>.<\/p>\n<p>The <a href=\"https:\/\/github.com\/swagger-api\/swagger-js\" target=\"_blank\" rel=\"noopener noreferrer\">Swagger JS client GitHub respository<\/a> has some useful documentation included.<\/p>\n<p>Find out about Swagger itself at <a href=\"https:\/\/swagger.io\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/swagger.io<\/a>.<\/p>\n<p>The online Swagger editor is really useful. You can generate client SDKs here, or even try out the API directly. Just paste the Swagger spec into the editor. <a href=\"https:\/\/editor.swagger.io\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/editor.swagger.io\/<\/a><\/p>\n<p>There\u2019s a React Native Couchbase community project that uses the JavaScript client. You can find some interesting examples there at <a href=\"https:\/\/github.com\/couchbaselabs\/react-native-couchbase-lite\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/github.com\/couchbaselabs\/react-native-couchbase-lite<\/a><\/p>\n<h2 id=\"postscript\">Postscript<\/h2>\n<p>Check out more resources on our <a href=\"https:\/\/www.couchbase.com\/developers\/community?utm_source=blogs&amp;utm_medium=link&amp;utm_campaign=blogs\" target=\"_blank\" rel=\"noopener noreferrer\">developer portal<\/a> and follow us on Twitter <a href=\"https:\/\/twitter.com\/CouchbaseDev\" target=\"_blank\" rel=\"noopener noreferrer\">@CouchbaseDev<\/a>.<\/p>\n<p>You can post questions on our <a href=\"https:\/\/www.couchbase.com\/forums\/?utm_source=blogs&amp;utm_medium=link&amp;utm_campaign=blogs\" target=\"_blank\" rel=\"noopener noreferrer\">forums<\/a>. And we actively participate on <a href=\"https:\/\/stackoverflow.com\/questions\/tagged\/couchbase\" target=\"_blank\" rel=\"noopener noreferrer\">Stack Overflow<\/a>.<\/p>\n<p>You can follow me personally at <a href=\"https:\/\/twitter.com\/HodGreeley\" target=\"_blank\" rel=\"noopener noreferrer\">@HodGreeley<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When building applications with Couchbase Mobile there are a lot of interesting possibilities for server-side integration. Creating business logic to resolve synchronization conflicts is one common use. The Sync Gateway document \u201cchanges\u201d feed makes all sorts of event-driven operations easy [&hellip;]<\/p>\n","protected":false},"author":73,"featured_media":13873,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1810,1822],"tags":[1790],"ppma_author":[9042],"class_list":["post-2494","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-couchbase-mobile","category-node-js","tag-swagger"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.2 (Yoast SEO v26.2) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Using Node.js and Swagger to Monitor Document Changes in Couchbase Mobile - The Couchbase Blog<\/title>\n<meta name=\"description\" content=\"This article shows how to use the Swagger Node.js client. Learn how to build a super simple app that monitors changes in documents in Couchbase.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using Node.js and Swagger to Monitor Document Changes in Couchbase Mobile\" \/>\n<meta property=\"og:description\" content=\"This article shows how to use the Swagger Node.js client. Learn how to build a super simple app that monitors changes in documents in Couchbase.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2017-01-19T21:43:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-10-09T14:23:21+00:00\" \/>\n<meta name=\"author\" content=\"Hod Greeley, Developer Advocate, Couchbase\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@HodGreeley\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Hod Greeley, Developer Advocate, Couchbase\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/\"},\"author\":{\"name\":\"Hod Greeley, Developer Advocate, Couchbase\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/9b62593c8a13531e53d52fcd5aabbca4\"},\"headline\":\"Using Node.js and Swagger to Monitor Document Changes in Couchbase Mobile\",\"datePublished\":\"2017-01-19T21:43:58+00:00\",\"dateModified\":\"2025-10-09T14:23:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/\"},\"wordCount\":1313,\"commentCount\":11,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"keywords\":[\"Swagger\"],\"articleSection\":[\"Couchbase Mobile\",\"Node.js\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/\",\"name\":\"Using Node.js and Swagger to Monitor Document Changes in Couchbase Mobile - The Couchbase Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"datePublished\":\"2017-01-19T21:43:58+00:00\",\"dateModified\":\"2025-10-09T14:23:21+00:00\",\"description\":\"This article shows how to use the Swagger Node.js client. Learn how to build a super simple app that monitors changes in documents in Couchbase.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"width\":1800,\"height\":630},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Using Node.js and Swagger to Monitor Document Changes in Couchbase Mobile\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/9b62593c8a13531e53d52fcd5aabbca4\",\"name\":\"Hod Greeley, Developer Advocate, Couchbase\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/21eb69cb5d4a401fb23b149e4f4e9e87\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/52d0018695c0ced0d1c68cf64a6195c81dbac03dce5983f98eb209e7c84350df?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/52d0018695c0ced0d1c68cf64a6195c81dbac03dce5983f98eb209e7c84350df?s=96&d=mm&r=g\",\"caption\":\"Hod Greeley, Developer Advocate, Couchbase\"},\"description\":\"Hod Greeley is a Developer Advocate for Couchbase, living in Silicon Valley. He has over two decades of experience as a software engineer and engineering manager. He has worked in a variety of software fields, including computational physics and chemistry, computer and network security, finance, and mobile. Prior to joining Couchbase in 2016, Hod led developer relations for mobile at Samsung. Hod holds a Ph.D. in chemical physics from Columbia University.\",\"sameAs\":[\"https:\/\/hod.greeley.org\/blog\",\"https:\/\/x.com\/HodGreeley\"],\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/hod-greeley\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Using Node.js and Swagger to Monitor Document Changes in Couchbase Mobile - The Couchbase Blog","description":"This article shows how to use the Swagger Node.js client. Learn how to build a super simple app that monitors changes in documents in Couchbase.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/","og_locale":"en_US","og_type":"article","og_title":"Using Node.js and Swagger to Monitor Document Changes in Couchbase Mobile","og_description":"This article shows how to use the Swagger Node.js client. Learn how to build a super simple app that monitors changes in documents in Couchbase.","og_url":"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/","og_site_name":"The Couchbase Blog","article_published_time":"2017-01-19T21:43:58+00:00","article_modified_time":"2025-10-09T14:23:21+00:00","author":"Hod Greeley, Developer Advocate, Couchbase","twitter_card":"summary_large_image","twitter_creator":"@HodGreeley","twitter_misc":{"Written by":"Hod Greeley, Developer Advocate, Couchbase","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/"},"author":{"name":"Hod Greeley, Developer Advocate, Couchbase","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/9b62593c8a13531e53d52fcd5aabbca4"},"headline":"Using Node.js and Swagger to Monitor Document Changes in Couchbase Mobile","datePublished":"2017-01-19T21:43:58+00:00","dateModified":"2025-10-09T14:23:21+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/"},"wordCount":1313,"commentCount":11,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","keywords":["Swagger"],"articleSection":["Couchbase Mobile","Node.js"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/","url":"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/","name":"Using Node.js and Swagger to Monitor Document Changes in Couchbase Mobile - The Couchbase Blog","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","datePublished":"2017-01-19T21:43:58+00:00","dateModified":"2025-10-09T14:23:21+00:00","description":"This article shows how to use the Swagger Node.js client. Learn how to build a super simple app that monitors changes in documents in Couchbase.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","width":1800,"height":630},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/node-js-swagger-monitor-document-changes-couchbase-mobile\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Using Node.js and Swagger to Monitor Document Changes in Couchbase Mobile"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"The Couchbase Blog","description":"Couchbase, the NoSQL Database","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"The Couchbase Blog","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/9b62593c8a13531e53d52fcd5aabbca4","name":"Hod Greeley, Developer Advocate, Couchbase","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/21eb69cb5d4a401fb23b149e4f4e9e87","url":"https:\/\/secure.gravatar.com\/avatar\/52d0018695c0ced0d1c68cf64a6195c81dbac03dce5983f98eb209e7c84350df?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/52d0018695c0ced0d1c68cf64a6195c81dbac03dce5983f98eb209e7c84350df?s=96&d=mm&r=g","caption":"Hod Greeley, Developer Advocate, Couchbase"},"description":"Hod Greeley is a Developer Advocate for Couchbase, living in Silicon Valley. He has over two decades of experience as a software engineer and engineering manager. He has worked in a variety of software fields, including computational physics and chemistry, computer and network security, finance, and mobile. Prior to joining Couchbase in 2016, Hod led developer relations for mobile at Samsung. Hod holds a Ph.D. in chemical physics from Columbia University.","sameAs":["https:\/\/hod.greeley.org\/blog","https:\/\/x.com\/HodGreeley"],"url":"https:\/\/www.couchbase.com\/blog\/author\/hod-greeley\/"}]}},"authors":[{"term_id":9042,"user_id":73,"is_guest":0,"slug":"hod-greeley","display_name":"Hod Greeley, Developer Advocate, Couchbase","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/52d0018695c0ced0d1c68cf64a6195c81dbac03dce5983f98eb209e7c84350df?s=96&d=mm&r=g","author_category":"","last_name":"Greeley","first_name":"Hod","job_title":"","user_url":"https:\/\/hod.greeley.org\/blog","description":"Hod Greeley is a Developer Advocate for Couchbase, living in Silicon Valley. He has over two decades of experience as a software engineer and engineering manager. He has worked in a variety of software fields, including computational physics and chemistry, computer and network security, finance, and mobile. Prior to joining Couchbase in 2016, Hod led developer relations for mobile at Samsung. Hod holds a Ph.D. in chemical physics from Columbia University."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/2494","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/users\/73"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=2494"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/2494\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/13873"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=2494"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=2494"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=2494"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=2494"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}