{"id":11742,"date":"2021-09-06T00:00:31","date_gmt":"2021-09-06T07:00:31","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=11742"},"modified":"2025-06-13T21:22:58","modified_gmt":"2025-06-14T04:22:58","slug":"build-a-rest-api-with-node-js-express-and-couchbase","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/","title":{"rendered":"Build a REST-Based Application with Node.js, Express and Couchbase"},"content":{"rendered":"<p><strong>If you&#8217;re new to Node.js, Couchbase<\/strong> or both, you&#8217;re about to level up your skills.<\/p>\n<p>Today I&#8217;ll show you how to build a minimal REST-based application for retrieving documents from Couchbase using Node.js and Express.<\/p>\n<p>This post continues my introductory series on <a href=\"https:\/\/www.couchbase.com\/blog\/get-started-nodejs-sdk-couchbase\/?ref=blog\" target=\"_blank\" rel=\"noopener\">using Node.js with Couchbase<\/a> (including <a href=\"https:\/\/www.couchbase.com\/blog\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/?ref=blog\" target=\"_blank\" rel=\"noopener\">last week&#8217;s post on async functions<\/a>).<\/p>\n<p>In today&#8217;s post, we&#8217;ll build on my previous examples of using Node.js and <a href=\"https:\/\/www.couchbase.com\/products\/capella\/\" target=\"_blank\" rel=\"noopener\">Couchbase<\/a>, so check out those two earlier articles if you haven&#8217;t already. I&#8217;ll also assume you have basic familiarity with JavaScript, Node.js and NoSQL document databases.<\/p>\n<h2>Get the Express Module<\/h2>\n<p>Starting from where we left off last week, we can add a web-based REST interface to help isolate your web application from the database. To do this, you need the Express module. Install it and add it to your package dependencies using:<\/p>\n<pre>npm install express --save\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>To test that Express is installed correctly, you can build a small application (<code>app.js<\/code>) that creates the HTTP server and returns a `Hello World` value. For later convenience, wrap it with an `async` function as you can see below:<\/p>\n<pre>var app = require('express')();\r\nconst couchbase = require(\"couchbase\");\r\n\r\nasync function main(){\r\n  app.get('\/', (req, res) =&gt; res.send('Hello world!'));\r\n  app.listen(3000, () =&gt; console.log('Listening on port 3000'));\r\n}\r\n\r\nmain();\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>Launch it and access it through a web browser on port 3000. It should look something like this image below:<\/p>\n<pre>node app.js<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p><a href=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/08\/hello-world-node-express-couchbase.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-11743\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/08\/hello-world-node-express-couchbase.png\" alt=\"Hello world showing in a web browser from Node.js and Express\" width=\"734\" height=\"577\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/hello-world-node-express-couchbase.png 734w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/hello-world-node-express-couchbase-300x236.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/hello-world-node-express-couchbase-20x16.png 20w\" sizes=\"auto, (max-width: 734px) 100vw, 734px\" \/><\/a><\/p>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>Congratulations! You&#8217;ve successfully built your first Express app, albeit a small one.<\/p>\n<h2>Building the Application<\/h2>\n<p>The application has three components:<\/p>\n<ul>\n<li style=\"list-style-type: none\">\n<ul>\n<li>Route management<\/li>\n<li>Database connectivity<\/li>\n<li>The HTTP server layer<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<h3>Add an Express Route for Data Retrieval<\/h3>\n<p>The application intercepts and serves the root path `\/`. We\u2019ll create a route called <code>get<\/code> for retrieving a specific document. The REST user provides a document ID and returns <a href=\"https:\/\/www.couchbase.com\/blog\/json-database\/?ref=blog\" target=\"_blank\" rel=\"noopener\">the JSON document<\/a> using the following syntax:<\/p>\n<pre>localhost:3000\/get\/[documentID]<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>The function for creating that route includes two important objects \u2013 <code>req<\/code> (request) and <code>res<\/code> (results) \u2013 which we&#8217;ll use for getting data to and from the app. See the example below:<\/p>\n<pre>  app.get('\/get\/:docid', \r\n    runAsync(async (req, res) =&gt; {\r\n      var docid = req.params.docid;\r\n      var docjson = await getDoc(docid, function(err, result){\r\n        res.json(result.content)\r\n      });\r\n  }));\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>Notice that the <code>:docid<\/code> parameter becomes a variable you can access through the request object: <code>var docid = req.params.docid<\/code>. It is then passed to the <code>getDoc()<\/code> function which we\u2019ll cover in a minute.<\/p>\n<p>The application also has this convenience function below for running everything asynchronously:<\/p>\n<pre>  function runAsync (callback) {\r\n    return function (req, res, next) {\r\n      callback(req, res, next)\r\n      .catch(next)\r\n    }\r\n  }\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>The function above wraps your calls nicely but I won&#8217;t explain it in detail here (maybe in a future post). For now, just add it to the script.<\/p>\n<h3>Add a Document-Retrieval Function<\/h3>\n<p>The database connectivity in the script is as basic as the earlier posts in this series. Select a <a href=\"https:\/\/www.couchbase.com\/blog\/scopes-and-collections-for-modern-multi-tenant-applications-couchbase-7-0\/?ref=blog\" target=\"_blank\" rel=\"noopener\">Bucket and Collection<\/a>, then use the <code>get()<\/code> function to retrieve a document based on a given document ID.<\/p>\n<p>First comes the connectivity piece. If you have a different username, password, Bucket or Collection, substitute it here:<\/p>\n<pre>  var cluster = new couchbase.Cluster(\"couchbase:\/\/localhost\", {\r\n    username: \"Administrator\",\r\n    password: \"Administrator\"\r\n  });\r\n\r\n  var bucket = cluster.bucket(\"travel-sample\");\r\n  var collection = bucket.defaultCollection();\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>Note that I host the app on a server on my network that also hosts the database (<code>localhost<\/code>). But I access the app from my dev laptop, so in the web browser samples below you&#8217;ll see the IP address <code>192.168.0.158<\/code> hitting the REST API.<\/p>\n<p>Now let\u2019s look at the main function for document retrieval:<\/p>\n<pre>  var getDoc = async (key) =&gt; {\r\n      var result = await collection.get(key);\r\n      console.log(result)\r\n      return result\r\n  };\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>We use the <code>collection<\/code> variable, which is the Couchbase database connection to the Bucket, etc., defined earlier. The <code>get()<\/code> function takes one input: a string with a document ID. For example, we used <code>hotel_5336<\/code> in the previous posts in this series.<\/p>\n<h3>Running the REST API<\/h3>\n<p>The HTTP server for the REST API still needs to run as well. It hasn&#8217;t changed since the first test app in this post:<\/p>\n<pre>app.listen(3000, () =&gt; console.log('Listening on port 3000'));\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>That covers all the code; a full listing is included below. Now you can run the server as before (<code> node app.js<\/code>) and provide a document ID through the web browser \u2013 e.g., <code>https:\/\/192.168.0.158:3000\/get\/hotel_5336<\/code>.<\/p>\n<p>The requested document is printed in the console and returned to the browser:<\/p>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p><a href=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/08\/get-function-node-express-couchbase.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium_large wp-image-11744\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/08\/get-function-node-express-couchbase-768x748.png\" alt=\"Database retrieval REST API with Node.js and Couchbase\" width=\"768\" height=\"748\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/get-function-node-express-couchbase-768x748.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/get-function-node-express-couchbase-300x292.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/get-function-node-express-couchbase-50x50.png 50w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/get-function-node-express-couchbase-20x20.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/get-function-node-express-couchbase.png 960w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a><\/p>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<h2>Full Code Sample<\/h2>\n<pre>var app = require('express')();\r\n\r\nvar couchbase = require(\"couchbase\");\r\n\r\nasync function main(){\r\n\r\n  app.get('\/get\/:docid',\r\n    runAsync(async (req, res) =&gt; {\r\n      var docid = req.params.docid;\r\n      var docjson = await getDoc(docid, function(err, result){\r\n        res.json(result.content)\r\n      });\r\n\r\n      res.json(docjson.content);\r\n  }));\r\n\r\n  app.listen(3000, () =&gt; console.log('Listening on port 3000'));\r\n\r\n  function runAsync (callback) {\r\n    return function (req, res, next) {\r\n      callback(req, res, next)\r\n      .catch(next)\r\n    }\r\n  }\r\n\r\n  var cluster = new couchbase.Cluster(\"couchbase:\/\/localhost\", {\r\n    username: \"Administrator\",\r\n    password: \"Administrator\"\r\n  });\r\n\r\n  var bucket = cluster.bucket(\"travel-sample\");\r\n  var collection = bucket.defaultCollection();\r\n\r\n  var getDoc = async (key) =&gt; {\r\n      var result = await collection.get(key);\r\n      console.log(result)\r\n      return result\r\n  };\r\n\r\n}\r\n\r\nmain();\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<h2>Conclusion<\/h2>\n<p>In future posts I&#8217;ll cover how to build a database query, conduct full-text searches and more \u2013 all using different Express routes.<\/p>\n<p>In the meantime, take your application to the next level by doing some of the following:<\/p>\n<ul>\n<li style=\"list-style-type: none\">\n<ul>\n<li>Add error capturing.<\/li>\n<li>Create a authentication system, such as JSON Web Token or JWT (see <a href=\"https:\/\/docs.couchbase.com\/nodejs-sdk\/current\/hello-world\/sample-application.html?ref=blog\" target=\"_blank\" rel=\"noopener\">this travel-sample demo project<\/a>).<\/li>\n<li>Read up on <a href=\"https:\/\/developer.couchbase.com\/topic\/nodejs\/?ref=blog\" target=\"_blank\" rel=\"noopener\">other Couchbase Node.js SDK functions<\/a> you can add to the app.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><em>Catch up with the rest of the Node.js + Couchbase how-to series:<\/em><\/p>\n<ul>\n<li style=\"list-style-type: none\">\n<ul>\n<li><a href=\"https:\/\/www.couchbase.com\/blog\/get-started-nodejs-sdk-couchbase\/?ref=blog\" target=\"_blank\" rel=\"noopener\">How to Get Started with the Node.js SDK for Couchbase<\/a><\/li>\n<li><a href=\"https:\/\/www.couchbase.com\/blog\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/?ref=blog\" target=\"_blank\" rel=\"noopener\">How to Create Async Get\/Upsert Calls with Node.js and Couchbase<\/a><\/li>\n<li><a href=\"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/?ref=blog\" target=\"_blank\" rel=\"noopener\">Build a REST-Based Application with Node.js, Express and Couchbase<\/a><\/li>\n<li><a href=\"https:\/\/www.couchbase.com\/blog\/how-to-query-json-data-n1ql-node-js-couchbase\/?ref=blog\" target=\"_blank\" rel=\"noopener\">How to Query JSON Data Using N1QL for Node.js and Couchbase<\/a><\/li>\n<li><a href=\"https:\/\/www.couchbase.com\/blog\/how-to-full-text-search-javascript-app\/?ref=blog\" target=\"_blank\" rel=\"noopener\">How to Add Full-Text Search Functionality to Your JavaScript App<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<div class=\"wp-block-spacer\" style=\"height: 30px\" aria-hidden=\"true\"><\/div>\n<div style=\"text-align: center\"><strong>Don&#8217;t just read about it \u2013 <em>try it out<\/em>:&lt;br\/ &gt;<a href=\"https:\/\/www.couchbase.com\/downloads\/?ref=blog\" target=\"_blank\" rel=\"noopener\">Download Couchbase and get building<\/a><\/strong><\/div>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re new to Node.js, Couchbase or both, you&#8217;re about to level up your skills. Today I&#8217;ll show you how to build a minimal REST-based application for retrieving documents from Couchbase using Node.js and Express. This post continues my introductory [&hellip;]<\/p>\n","protected":false},"author":75185,"featured_media":11851,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[9327,1822,9336,2201],"tags":[9400,2312,1254,1543,1261,1725,1950],"ppma_author":[9163],"class_list":["post-11742","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","category-node-js","category-scopes-and-collections","category-tools-sdks","tag-async-function","tag-document-database","tag-express","tag-javascript","tag-json","tag-nosql-database","tag-rest-api"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.0 (Yoast SEO v26.0) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Node.js, Express and Couchbase: Build REST-Based Application<\/title>\n<meta name=\"description\" content=\"Visit this post for best practices on how to build a minimal REST-based application for retrieving documents from Couchbase using Node.js and Express.\" \/>\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\/build-a-rest-api-with-node-js-express-and-couchbase\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Build a REST-Based Application with Node.js, Express and Couchbase\" \/>\n<meta property=\"og:description\" content=\"Visit this post for best practices on how to build a minimal REST-based application for retrieving documents from Couchbase using Node.js and Express.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2021-09-06T07:00:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T04:22:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/how-to-build-rest-api-based-application-nodejs-express-couchbase-social.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Tyler Mitchell - Senior Product Marketing Manager\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/how-to-build-rest-api-based-application-nodejs-express-couchbase-social.png\" \/>\n<meta name=\"twitter:creator\" content=\"@1tylermitchell\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Tyler Mitchell - Senior Product Marketing Manager\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"TechArticle\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/\"},\"author\":{\"name\":\"Tyler Mitchell - Senior Product Marketing Manager\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/684cc0e5c60cd2e4b591db9621494ed0\"},\"headline\":\"Build a REST-Based Application with Node.js, Express and Couchbase\",\"datePublished\":\"2021-09-06T07:00:31+00:00\",\"dateModified\":\"2025-06-14T04:22:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/\"},\"wordCount\":771,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/how-to-build-rest-api-based-application-nodejs-express-couchbase.png\",\"keywords\":[\"async function\",\"document database\",\"express\",\"javascript\",\"JSON\",\"NoSQL Database\",\"REST API\"],\"articleSection\":[\"JavaScript\",\"Node.js\",\"Scopes and Collections\",\"Tools &amp; SDKs\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/\",\"name\":\"Node.js, Express and Couchbase: Build REST-Based Application\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/how-to-build-rest-api-based-application-nodejs-express-couchbase.png\",\"datePublished\":\"2021-09-06T07:00:31+00:00\",\"dateModified\":\"2025-06-14T04:22:58+00:00\",\"description\":\"Visit this post for best practices on how to build a minimal REST-based application for retrieving documents from Couchbase using Node.js and Express.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/how-to-build-rest-api-based-application-nodejs-express-couchbase.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/how-to-build-rest-api-based-application-nodejs-express-couchbase.png\",\"width\":1200,\"height\":628,\"caption\":\"Build a REST API application that uses Node.js, Express and Couchbase to retrieve documents\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Build a REST-Based Application with Node.js, Express and Couchbase\"}]},{\"@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\/684cc0e5c60cd2e4b591db9621494ed0\",\"name\":\"Tyler Mitchell - Senior Product Marketing Manager\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/d8a7c532bf2b94b7a2fe7a8439aafd75\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ebec3213e756f2e1f7118fcb5722e2cd1484c9256ae34ceb8f77054b986f21ce?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ebec3213e756f2e1f7118fcb5722e2cd1484c9256ae34ceb8f77054b986f21ce?s=96&d=mm&r=g\",\"caption\":\"Tyler Mitchell - Senior Product Marketing Manager\"},\"description\":\"Works as Senior Product Marketing Manager at Couchbase, helping bring knowledge about products into the public limelight while also supporting our field teams with valuable content. His personal passion is all things geospatial, having worked in GIS for half his career. Now AI and Vector Search is top of mind.\",\"sameAs\":[\"https:\/\/linkedin.com\/in\/tylermitchell\",\"https:\/\/x.com\/1tylermitchell\",\"https:\/\/www.youtube.com\/channel\/UCBZFuoiTcg0f3lGSQwLjeTg\"],\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/tylermitchell\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Node.js, Express and Couchbase: Build REST-Based Application","description":"Visit this post for best practices on how to build a minimal REST-based application for retrieving documents from Couchbase using Node.js and Express.","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\/build-a-rest-api-with-node-js-express-and-couchbase\/","og_locale":"en_US","og_type":"article","og_title":"Build a REST-Based Application with Node.js, Express and Couchbase","og_description":"Visit this post for best practices on how to build a minimal REST-based application for retrieving documents from Couchbase using Node.js and Express.","og_url":"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/","og_site_name":"The Couchbase Blog","article_published_time":"2021-09-06T07:00:31+00:00","article_modified_time":"2025-06-14T04:22:58+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/how-to-build-rest-api-based-application-nodejs-express-couchbase-social.png","type":"image\/png"}],"author":"Tyler Mitchell - Senior Product Marketing Manager","twitter_card":"summary_large_image","twitter_image":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/how-to-build-rest-api-based-application-nodejs-express-couchbase-social.png","twitter_creator":"@1tylermitchell","twitter_misc":{"Written by":"Tyler Mitchell - Senior Product Marketing Manager","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"TechArticle","@id":"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/"},"author":{"name":"Tyler Mitchell - Senior Product Marketing Manager","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/684cc0e5c60cd2e4b591db9621494ed0"},"headline":"Build a REST-Based Application with Node.js, Express and Couchbase","datePublished":"2021-09-06T07:00:31+00:00","dateModified":"2025-06-14T04:22:58+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/"},"wordCount":771,"commentCount":1,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/how-to-build-rest-api-based-application-nodejs-express-couchbase.png","keywords":["async function","document database","express","javascript","JSON","NoSQL Database","REST API"],"articleSection":["JavaScript","Node.js","Scopes and Collections","Tools &amp; SDKs"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/","url":"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/","name":"Node.js, Express and Couchbase: Build REST-Based Application","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/how-to-build-rest-api-based-application-nodejs-express-couchbase.png","datePublished":"2021-09-06T07:00:31+00:00","dateModified":"2025-06-14T04:22:58+00:00","description":"Visit this post for best practices on how to build a minimal REST-based application for retrieving documents from Couchbase using Node.js and Express.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/how-to-build-rest-api-based-application-nodejs-express-couchbase.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/how-to-build-rest-api-based-application-nodejs-express-couchbase.png","width":1200,"height":628,"caption":"Build a REST API application that uses Node.js, Express and Couchbase to retrieve documents"},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Build a REST-Based Application with Node.js, Express and Couchbase"}]},{"@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\/684cc0e5c60cd2e4b591db9621494ed0","name":"Tyler Mitchell - Senior Product Marketing Manager","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/d8a7c532bf2b94b7a2fe7a8439aafd75","url":"https:\/\/secure.gravatar.com\/avatar\/ebec3213e756f2e1f7118fcb5722e2cd1484c9256ae34ceb8f77054b986f21ce?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ebec3213e756f2e1f7118fcb5722e2cd1484c9256ae34ceb8f77054b986f21ce?s=96&d=mm&r=g","caption":"Tyler Mitchell - Senior Product Marketing Manager"},"description":"Works as Senior Product Marketing Manager at Couchbase, helping bring knowledge about products into the public limelight while also supporting our field teams with valuable content. His personal passion is all things geospatial, having worked in GIS for half his career. Now AI and Vector Search is top of mind.","sameAs":["https:\/\/linkedin.com\/in\/tylermitchell","https:\/\/x.com\/1tylermitchell","https:\/\/www.youtube.com\/channel\/UCBZFuoiTcg0f3lGSQwLjeTg"],"url":"https:\/\/www.couchbase.com\/blog\/author\/tylermitchell\/"}]}},"authors":[{"term_id":9163,"user_id":75185,"is_guest":0,"slug":"tylermitchell","display_name":"Tyler Mitchell - Senior Product Marketing Manager","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/876da1e4284f1832c871b3514caf7867357744b8c0a370ef6f53a79dee2f379e?s=96&d=mm&r=g","author_category":"","last_name":"Mitchell - Senior Product Marketing Manager","first_name":"Tyler","job_title":"Senior Product Marketing Manager","user_url":"","description":"Works as Senior Product Marketing Manager at Couchbase, helping bring knowledge about products into the public limelight while also supporting our field teams with valuable content. His personal passion is all things geospatial, having worked in GIS for half his career. Now AI and Vector Search is top of mind."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/11742","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\/75185"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=11742"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/11742\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/11851"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=11742"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=11742"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=11742"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=11742"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}