{"id":261,"date":"2022-03-09T11:50:38","date_gmt":"2022-03-09T11:50:38","guid":{"rendered":"https:\/\/www.kindsonthegenius.com\/nodejs\/?p=261"},"modified":"2022-03-10T09:42:19","modified_gmt":"2022-03-10T09:42:19","slug":"node-js-create-a-node-js-api-using-typescript-part-2-postgresql","status":"publish","type":"post","link":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-create-a-node-js-api-using-typescript-part-2-postgresql\/","title":{"rendered":"Node.js &#8211; Create a Node.js API and TypeScript (Part 2 &#8211; PostgreSQL)"},"content":{"rendered":"<p>In this tutorial, we would connect to PostgreSQL and write the function to perform CRUD operations using TypeScript.<\/p>\n<ol>\n<li><a href=\"#t1\">GET Request for List of Countries<\/a><\/li>\n<li><a href=\"#t2\">Integrate the Routing into the Controller<\/a><\/li>\n<li><a href=\"#t3\">GET Country by Id<\/a><\/li>\n<li><a href=\"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-rest-api-with-typescript-part-3-post-put-delete\/#t1\">Make a POST Request<\/a><\/li>\n<li><a href=\"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-rest-api-with-typescript-part-3-post-put-delete\/#t2\">Make an UPDATE<\/a><\/li>\n<li><a href=\"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-rest-api-with-typescript-part-3-post-put-delete\/#t3\">DELETE A Country<\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t1\">1. GET Request for List of Countries<\/strong><\/h4>\n<p><strong>Step 1<\/strong> &#8211; Inside the src folder, create a file named<strong> connection.ts<\/strong>. This would contain the connection parameters for PostgreSQL. The content is given below:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">import<\/span> pgPromise from <span style=\"background-color: #fff0f0;\">'pg-promise'<\/span>;\r\n<span style=\"color: #008800; font-weight: bold;\">const<\/span> pg <span style=\"color: #333333;\">=<\/span> pgPromise({});\r\n<span style=\"color: #008800; font-weight: bold;\">export<\/span> <span style=\"color: #008800; font-weight: bold;\">const<\/span> db <span style=\"color: #333333;\">=<\/span> pg(<span style=\"background-color: #fff0f0;\">\"postgres:\/\/postgres:password@localhost:5432\/fleetdb\"<\/span>);\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 2<\/strong> &#8211; Install <em><strong>pg-promise<\/strong><\/em> using npm<\/p>\n<p><strong>Step 3<\/strong> &#8211; Create a file inside the services folder named <strong>country-service.ts<\/strong>. This file would contain the functions that executes SQL statements to perform GET, POST, PUT and DELETE on the PostgreSQL database. For now, we write only the function to retrieve list of countries<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">import<\/span> {db} from <span style=\"background-color: #fff0f0;\">'..\/connection'<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">export<\/span> <span style=\"color: #008800; font-weight: bold;\">const<\/span> getCountries <span style=\"color: #333333;\">=<\/span> async () <span style=\"color: #333333;\">=&gt;<\/span> {\r\n    <span style=\"color: #008800; font-weight: bold;\">return<\/span> await db.query(<span style=\"background-color: #fff0f0;\">'SELECT * FROM Country'<\/span>)\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 4<\/strong> &#8211; Create a file country-controller inside the controllers folder and here, you write the code to call the getCountries function in the country-service and send it as a response to the the REST API GET request.<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">import<\/span> {Request, Response} from <span style=\"background-color: #fff0f0;\">'express'<\/span>;\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #333333;\">*<\/span> <span style=\"color: #008800; font-weight: bold;\">as<\/span> countryService from <span style=\"background-color: #fff0f0;\">'..\/services\/country-service'<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">const<\/span> getCountries <span style=\"color: #333333;\">=<\/span> async (req: <span style=\"color: #333399; font-weight: bold;\">Request<\/span>, res: <span style=\"color: #333399; font-weight: bold;\">Response<\/span>) <span style=\"color: #333333;\">=&gt;<\/span> {\r\n    countryService.getCountries().then(\r\n        (countries) <span style=\"color: #333333;\">=&gt;<\/span> {\r\n            res.send(countries);\r\n        }\r\n    )\r\n};\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">export<\/span> <span style=\"color: #008800; font-weight: bold;\">default<\/span> {getCountries}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 5<\/strong> &#8211; You now need to modify the app-routes file to include the \/countries route. The content would now be:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">import<\/span> express from <span style=\"background-color: #fff0f0;\">'express'<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> controller from <span style=\"background-color: #fff0f0;\">'..\/controllers\/home-controller'<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> countryController from <span style=\"background-color: #fff0f0;\">'..\/controllers\/country-controller'<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">const<\/span> router <span style=\"color: #333333;\">=<\/span> express.Router();\r\n\r\nrouter.get(<span style=\"background-color: #fff0f0;\">'\/home'<\/span>, controller.getHome);\r\nrouter.get(<span style=\"background-color: #fff0f0;\">'\/countries'<\/span>, countryController.getCountries)\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">export<\/span> <span style=\"color: #333333;\">=<\/span> router;\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>A this point, you can start the application and visit the \/countries route. You&#8217;ll sure to get list of countries as response.<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t2\">2. Integrate Routing into the Controller<\/strong><\/h4>\n<p>You notice that we have a separate file for route and controller. Now we would integrate the two and therefore, we&#8217;ll not need the app-routes.ts file. To to this follow the steps:<\/p>\n<p><strong>Step 1<\/strong> &#8211; Delete the routes directory. This is because we would now have to specify the routes in the controller files just like in Spring Boot!<\/p>\n<p><strong>Step 2<\/strong> &#8211; Modify the <em><strong>home-controller.ts<\/strong><\/em> file to include router like so.<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">const<\/span> router <span style=\"color: #333333;\">=<\/span> express.Router();\r\n\r\nrouter.get(<span style=\"background-color: #fff0f0;\">'\/home'<\/span>, (req: <span style=\"color: #333399; font-weight: bold;\">Request<\/span>, res: <span style=\"color: #333399; font-weight: bold;\">Response<\/span>) <span style=\"color: #333333;\">=&gt;<\/span> {\r\n    <span style=\"color: #008800; font-weight: bold;\">return<\/span> res.send(service.goHome());\r\n})\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">export<\/span> <span style=\"color: #008800; font-weight: bold;\">default<\/span> router\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 3<\/strong> &#8211; Also modify the country-controller to include router like this:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">const<\/span> router <span style=\"color: #333333;\">=<\/span> express.Router();\r\n\r\nrouter.get(<span style=\"background-color: #fff0f0;\">'\/countries'<\/span>, (req: <span style=\"color: #333399; font-weight: bold;\">Request<\/span>, res: <span style=\"color: #333399; font-weight: bold;\">Response<\/span>) <span style=\"color: #333333;\">=&gt;<\/span> {\r\n    countryService.getCountries().then(\r\n        (countries) <span style=\"color: #333333;\">=&gt;<\/span> {\r\n            res.send(countries);\r\n        }\r\n    );\r\n});\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">export<\/span> <span style=\"color: #008800; font-weight: bold;\">default<\/span> router\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 4<\/strong> &#8211; You now need to modify the server.ts file to now use the routes defined in the controller files. The server.ts file would now be:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">import<\/span> http from <span style=\"background-color: #fff0f0;\">'http'<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> express, {Express} from <span style=\"background-color: #fff0f0;\">'express'<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #333333;\">*<\/span> <span style=\"color: #008800; font-weight: bold;\">as<\/span> homeController from <span style=\"background-color: #fff0f0;\">'.\/controllers\/home-controller'<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #333333;\">*<\/span> <span style=\"color: #008800; font-weight: bold;\">as<\/span> countryController from <span style=\"background-color: #fff0f0;\">'.\/controllers\/country-controller'<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">const<\/span> router: <span style=\"color: #333399; font-weight: bold;\">Express<\/span> <span style=\"color: #333333;\">=<\/span> express();\r\n\r\nrouter.use(<span style=\"background-color: #fff0f0;\">''<\/span>,\r\n    homeController.<span style=\"color: #008800; font-weight: bold;\">default<\/span>,\r\n    countryController.<span style=\"color: #008800; font-weight: bold;\">default<\/span>\r\n)\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">const<\/span> httpServer <span style=\"color: #333333;\">=<\/span> http.createServer(router)\r\n\r\nhttpServer.listen(<span style=\"color: #0000dd; font-weight: bold;\">6060<\/span>, ()<span style=\"color: #333333;\">=&gt;<\/span>{\r\n    console.log(<span style=\"color: #ff0000; background-color: #ffaaaa;\">`<\/span>Server is running at port <span style=\"color: #0000dd; font-weight: bold;\">6060<\/span><span style=\"color: #ff0000; background-color: #ffaaaa;\">`<\/span>);\r\n})\r\n<\/pre>\n<p>You can now test the application once again to make sure everything works.<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t3\">3. Get Countries by Id<\/strong><\/h4>\n<p>Now we want to see how we can pass a url parameter across to the controller.<\/p>\n<p><strong>Step 1<\/strong> &#8211; Create a method getCountryById in the country-service.ts file<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">export<\/span> async <span style=\"color: #008800; font-weight: bold;\">function<\/span> getCountryById(id: <span style=\"color: #333399; font-weight: bold;\">number<\/span>) {\r\n    <span style=\"color: #008800; font-weight: bold;\">return<\/span> await db.any(<span style=\"background-color: #fff0f0;\">'SELECT * FROM Country WHERE id = $1'<\/span>, [id])\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 2<\/strong> &#8211; Create\u00a0 function in the country-controller like this:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">router.get(<span style=\"background-color: #fff0f0;\">'\/countries\/:id'<\/span>, (req: <span style=\"color: #333399; font-weight: bold;\">Request<\/span>, res: <span style=\"color: #333399; font-weight: bold;\">Response<\/span>) <span style=\"color: #333333;\">=&gt;<\/span> {\r\n    countryService.getCountryById(<span style=\"color: #007020;\">parseInt<\/span>(req.params.id)).then(\r\n        (country) <span style=\"color: #333333;\">=&gt;<\/span> {\r\n            res.send(country);\r\n        }\r\n    );\r\n});\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>At this point, you can test the application to and access the url \/countries\/1.<\/p>\n<p>In the next part, we would write the methods to perform POST, PUT and DELETE operation.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we would connect to PostgreSQL and write the function to perform CRUD operations using TypeScript. GET Request for List of Countries Integrate &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[32,11,31],"class_list":["post-261","post","type-post","status-publish","format-standard","hentry","category-node-js-tutorials","tag-postgresql","tag-rest-api","tag-typescript"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Node.js - Create a Node.js API and TypeScript (Part 2 - PostgreSQL) - Node.js Tutorials<\/title>\n<meta name=\"description\" content=\"In this tutorial, you will create a REST API in Node.js and write the methods to get list of countries and getById\" \/>\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.kindsonthegenius.com\/nodejs\/node-js-create-a-node-js-api-using-typescript-part-2-postgresql\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Node.js - Create a Node.js API and TypeScript (Part 2 - PostgreSQL) - Node.js Tutorials\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, you will create a REST API in Node.js and write the methods to get list of countries and getById\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-create-a-node-js-api-using-typescript-part-2-postgresql\/\" \/>\n<meta property=\"og:site_name\" content=\"Node.js Tutorials\" \/>\n<meta property=\"article:published_time\" content=\"2022-03-09T11:50:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-03-10T09:42:19+00:00\" \/>\n<meta name=\"author\" content=\"kindsonthegenius\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"kindsonthegenius\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-create-a-node-js-api-using-typescript-part-2-postgresql\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-create-a-node-js-api-using-typescript-part-2-postgresql\\\/\"},\"author\":{\"name\":\"kindsonthegenius\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/#\\\/schema\\\/person\\\/7f8fc5792578d2ff54003fcebe6c46b5\"},\"headline\":\"Node.js &#8211; Create a Node.js API and TypeScript (Part 2 &#8211; PostgreSQL)\",\"datePublished\":\"2022-03-09T11:50:38+00:00\",\"dateModified\":\"2022-03-10T09:42:19+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-create-a-node-js-api-using-typescript-part-2-postgresql\\\/\"},\"wordCount\":429,\"commentCount\":0,\"keywords\":[\"PostgreSQL\",\"REST API\",\"TypeScript\"],\"articleSection\":[\"Node.js Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-create-a-node-js-api-using-typescript-part-2-postgresql\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-create-a-node-js-api-using-typescript-part-2-postgresql\\\/\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-create-a-node-js-api-using-typescript-part-2-postgresql\\\/\",\"name\":\"Node.js - Create a Node.js API and TypeScript (Part 2 - PostgreSQL) - Node.js Tutorials\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/#website\"},\"datePublished\":\"2022-03-09T11:50:38+00:00\",\"dateModified\":\"2022-03-10T09:42:19+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/#\\\/schema\\\/person\\\/7f8fc5792578d2ff54003fcebe6c46b5\"},\"description\":\"In this tutorial, you will create a REST API in Node.js and write the methods to get list of countries and getById\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-create-a-node-js-api-using-typescript-part-2-postgresql\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-create-a-node-js-api-using-typescript-part-2-postgresql\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-create-a-node-js-api-using-typescript-part-2-postgresql\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Node.js &#8211; Create a Node.js API and TypeScript (Part 2 &#8211; PostgreSQL)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/#website\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/\",\"name\":\"Node.js Tutorials\",\"description\":\"Best Node.js Tutorials\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/#\\\/schema\\\/person\\\/7f8fc5792578d2ff54003fcebe6c46b5\",\"name\":\"kindsonthegenius\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"caption\":\"kindsonthegenius\"},\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/author\\\/kindsonthegenius-3\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Node.js - Create a Node.js API and TypeScript (Part 2 - PostgreSQL) - Node.js Tutorials","description":"In this tutorial, you will create a REST API in Node.js and write the methods to get list of countries and getById","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.kindsonthegenius.com\/nodejs\/node-js-create-a-node-js-api-using-typescript-part-2-postgresql\/","og_locale":"en_US","og_type":"article","og_title":"Node.js - Create a Node.js API and TypeScript (Part 2 - PostgreSQL) - Node.js Tutorials","og_description":"In this tutorial, you will create a REST API in Node.js and write the methods to get list of countries and getById","og_url":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-create-a-node-js-api-using-typescript-part-2-postgresql\/","og_site_name":"Node.js Tutorials","article_published_time":"2022-03-09T11:50:38+00:00","article_modified_time":"2022-03-10T09:42:19+00:00","author":"kindsonthegenius","twitter_card":"summary_large_image","twitter_misc":{"Written by":"kindsonthegenius","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-create-a-node-js-api-using-typescript-part-2-postgresql\/#article","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-create-a-node-js-api-using-typescript-part-2-postgresql\/"},"author":{"name":"kindsonthegenius","@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/#\/schema\/person\/7f8fc5792578d2ff54003fcebe6c46b5"},"headline":"Node.js &#8211; Create a Node.js API and TypeScript (Part 2 &#8211; PostgreSQL)","datePublished":"2022-03-09T11:50:38+00:00","dateModified":"2022-03-10T09:42:19+00:00","mainEntityOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-create-a-node-js-api-using-typescript-part-2-postgresql\/"},"wordCount":429,"commentCount":0,"keywords":["PostgreSQL","REST API","TypeScript"],"articleSection":["Node.js Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-create-a-node-js-api-using-typescript-part-2-postgresql\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-create-a-node-js-api-using-typescript-part-2-postgresql\/","url":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-create-a-node-js-api-using-typescript-part-2-postgresql\/","name":"Node.js - Create a Node.js API and TypeScript (Part 2 - PostgreSQL) - Node.js Tutorials","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/#website"},"datePublished":"2022-03-09T11:50:38+00:00","dateModified":"2022-03-10T09:42:19+00:00","author":{"@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/#\/schema\/person\/7f8fc5792578d2ff54003fcebe6c46b5"},"description":"In this tutorial, you will create a REST API in Node.js and write the methods to get list of countries and getById","breadcrumb":{"@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-create-a-node-js-api-using-typescript-part-2-postgresql\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-create-a-node-js-api-using-typescript-part-2-postgresql\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-create-a-node-js-api-using-typescript-part-2-postgresql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.kindsonthegenius.com\/nodejs\/"},{"@type":"ListItem","position":2,"name":"Node.js &#8211; Create a Node.js API and TypeScript (Part 2 &#8211; PostgreSQL)"}]},{"@type":"WebSite","@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/#website","url":"https:\/\/www.kindsonthegenius.com\/nodejs\/","name":"Node.js Tutorials","description":"Best Node.js Tutorials","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.kindsonthegenius.com\/nodejs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/#\/schema\/person\/7f8fc5792578d2ff54003fcebe6c46b5","name":"kindsonthegenius","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","caption":"kindsonthegenius"},"url":"https:\/\/www.kindsonthegenius.com\/nodejs\/author\/kindsonthegenius-3\/"}]}},"_links":{"self":[{"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/posts\/261","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/comments?post=261"}],"version-history":[{"count":9,"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/posts\/261\/revisions"}],"predecessor-version":[{"id":277,"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/posts\/261\/revisions\/277"}],"wp:attachment":[{"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/media?parent=261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/categories?post=261"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/tags?post=261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}