{"id":18158,"date":"2024-04-11T05:56:48","date_gmt":"2024-04-11T12:56:48","guid":{"rendered":"https:\/\/ioflood.com\/blog\/?p=18158"},"modified":"2024-04-11T05:56:51","modified_gmt":"2024-04-11T12:56:51","slug":"npm-pg","status":"publish","type":"post","link":"https:\/\/ioflood.com\/blog\/npm-pg\/","title":{"rendered":"NPM PG Guide | Unlock PostgreSQL Power in Node.js"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"alignright size-full is-resized\"><img decoding=\"async\" src=\"https:\/\/ioflood.com\/blog\/wp-content\/uploads\/2024\/04\/Illustration-depicting-the-symbolic-interaction-between-a-Nodejs-application-and-a-PostgreSQL-database-300x300.jpg\" alt=\"Illustration depicting the symbolic interaction between a Nodejs application and a PostgreSQL database\" width=\"300\" height=\"300\" title=\"\"><\/figure>\n<\/div>\n<p>At IOFlood, integrating PostgreSQL databases into our Node.js applications was a common task. Now that we have solved this challenge, we&#8217;ve created a guide to help streamline the process. By following these instructions, you&#8217;ll confidently navigate PostgreSQL integration, enabling you to build scalable applications with ease.<\/p>\n<p><strong>This guide will walk you through the installation, basic usage, and advanced features of the &#8216;pg&#8217; package,<\/strong> enabling you to efficiently manage your PostgreSQL database. From setting up your first connection to diving deep into advanced database operations, we&#8217;ve got you covered.<\/p>\n<p>Let&#8217;s embark on this journey to unlock the full potential of PostgreSQL in your Node.js projects.<\/p>\n<h2>TL;DR: How Do I Start Using PostgreSQL in Node.js with &#8216;npm pg&#8217;?<\/h2>\n<blockquote><p>\n  To kickstart your PostgreSQL journey in Node.js, begin by installing the <code>npm pg<\/code> package with the command <code>npm install pg<\/code>. After installing you must <code>require<\/code> the <code>pg<\/code> module in your code and then use it to interact with your PostgreSQL database.\n<\/p><\/blockquote>\n<p>Here&#8217;s a quick example to get you started:<\/p>\n<pre><code class=\"language-javascript line-numbers\">const { Pool } = require('pg');\nconst pool = new Pool({\n  user: 'dbuser',\n  host: 'database.server.com',\n  database: 'mydb',\n  password: 'secretpassword',\n  port: 5432,\n});\n\n# Output:\n# Pool object with connection configuration\n<\/code><\/pre>\n<p>In this example, we import the <code>Pool<\/code> class from the &#8216;pg&#8217; package and create a new pool instance with our database connection details. This setup is crucial for managing multiple database connections efficiently, ensuring your Node.js app can communicate with your PostgreSQL database seamlessly.<\/p>\n<blockquote><p>\n  Eager to dive deeper? Continue reading for more detailed instructions and advanced usage tips that will elevate your database management skills.\n<\/p><\/blockquote>\n<h2>Getting Started with npm pg<\/h2>\n<h3>Installation and Connection Setup<\/h3>\n<p>Embarking on your PostgreSQL journey with Node.js begins with the foundational step of installing the &#8216;npm pg&#8217; package. This package acts as a bridge, facilitating communication between your Node.js application and PostgreSQL database.<\/p>\n<p>To install &#8216;npm pg&#8217;, open your terminal and run:<\/p>\n<pre><code class=\"language-bash line-numbers\">npm install pg\n\n# Output:\n# Adds the pg package to your project dependencies\n<\/code><\/pre>\n<p>Once installed, the next step is to establish a connection to your PostgreSQL database. Here&#8217;s how you can connect using the <code>Client<\/code> class provided by &#8216;npm pg&#8217;:<\/p>\n<pre><code class=\"language-javascript line-numbers\">const { Client } = require('pg');\nconst client = new Client({\n  connectionString: 'postgres:\/\/dbuser:secretpassword@localhost:5432\/mydb'\n});\nclient.connect();\n\n# Output:\n# Successfully connected to the database\n<\/code><\/pre>\n<p>In this example, we create a new <code>Client<\/code> instance and pass our database connection string. The <code>.connect()<\/code> method is then called to establish the connection. This step is crucial for executing queries against your database.<\/p>\n<h3>Executing Basic Queries<\/h3>\n<p>Once connected, you&#8217;re ready to execute basic SQL queries. A simple SELECT query can be used to retrieve data from your database:<\/p>\n<pre><code class=\"language-javascript line-numbers\">client.query('SELECT * FROM users;', (err, res) =&gt; {\n  if (err) throw err;\n  console.log(res.rows);\n});\n\n# Output:\n# Displays the rows retrieved from the 'users' table\n<\/code><\/pre>\n<p>This code snippet demonstrates how to execute a query and handle the response. The <code>query<\/code> method takes in your SQL query as a string and a callback function that processes the results. The output shows the rows fetched from the &#8216;users&#8217; table, illustrating the ease with which you can retrieve data.<\/p>\n<h3>Pros and Cons of Using &#8216;npm pg&#8217;<\/h3>\n<p><strong>Pros:<\/strong><br \/>\n&#8211; <strong>Simplicity:<\/strong> &#8216;npm pg&#8217; offers a straightforward approach to integrating PostgreSQL with Node.js, making it accessible for beginners.<br \/>\n&#8211; <strong>Flexibility:<\/strong> It supports a wide range of PostgreSQL features, from basic queries to advanced database operations.<\/p>\n<p><strong>Cons:<\/strong><br \/>\n&#8211; <strong>Learning Curve:<\/strong> While simple, mastering &#8216;npm pg&#8217; and understanding its nuances requires time and practice.<br \/>\n&#8211; <strong>Connection Management:<\/strong> Without proper handling, managing multiple database connections can become complex, especially in high-load scenarios.<\/p>\n<p>By understanding the basic use of &#8216;npm pg&#8217;, you&#8217;re now equipped to start managing your PostgreSQL database within Node.js applications. The journey from here involves exploring more advanced features and best practices, which will further enhance your database management capabilities.<\/p>\n<h2>Advanced Database Skills with npm pg<\/h2>\n<h3>Mastering Connection Pooling<\/h3>\n<p>Connection pooling is a crucial technique in managing database connections, especially in applications with high concurrency. It allows multiple clients to share a set of database connections, improving resource utilization and application performance.<\/p>\n<p>To implement connection pooling with &#8216;npm pg&#8217;, you utilize the <code>Pool<\/code> class. Here&#8217;s an example of setting up a pool and executing a query:<\/p>\n<pre><code class=\"language-javascript line-numbers\">const { Pool } = require('pg');\nconst pool = new Pool({\n  user: 'dbuser',\n  host: 'localhost',\n  database: 'mydb',\n  password: 'secretpassword',\n  port: 5432,\n});\n\npool.query('SELECT NOW()', (err, res) =&gt; {\n  if (err) throw err;\n  console.log('The current time is:', res.rows[0].now);\n});\n\n# Output:\n# The current time is: 2023-03-15T12:34:56.789Z\n<\/code><\/pre>\n<p>This snippet demonstrates how to create a pool of connections and execute a simple query to retrieve the current time from the database. The <code>pool.query<\/code> method automatically handles connection borrowing from the pool and returning it after the query completes. This approach significantly simplifies connection management in your application.<\/p>\n<h3>Transaction Management Mastery<\/h3>\n<p>Transactions are vital for maintaining data integrity, allowing multiple operations to be treated as a single atomic action. &#8216;npm pg&#8217; supports robust transaction management, enabling you to execute complex workflows with confidence.<\/p>\n<p>Here&#8217;s how you can manage transactions using &#8216;npm pg&#8217;:<\/p>\n<pre><code class=\"language-javascript line-numbers\">(async () =&gt; {\n  const client = await pool.connect();\n  try {\n    await client.query('BEGIN');\n    await client.query('INSERT INTO users(name) VALUES($1)', ['Alice']);\n    await client.query('COMMIT');\n  } catch (e) {\n    await client.query('ROLLBACK');\n    throw e;\n  } finally {\n    client.release();\n  }\n})();\n\n# Output:\n# Successfully inserted 'Alice' into the users table\n<\/code><\/pre>\n<p>This example showcases a simple transaction where a new user is inserted into the <code>users<\/code> table. The transaction is explicitly started with <code>BEGIN<\/code> and committed with <code>COMMIT<\/code>. In case of an error, the transaction is rolled back to maintain data consistency. The <code>client.release()<\/code> ensures the connection is returned to the pool, highlighting the importance of resource management.<\/p>\n<h3>Listening to PostgreSQL Notifications<\/h3>\n<p>&#8216;npm pg&#8217; also allows you to listen for PostgreSQL notifications, enabling real-time data updates and event-driven programming patterns. Implementing this feature can significantly enhance the interactivity of your Node.js applications.<\/p>\n<pre><code class=\"language-javascript line-numbers\">const client = new Client();\nclient.connect();\nclient.on('notification', (msg) =&gt; {\n  console.log('New notification:', msg);\n});\nclient.query('LISTEN my_notification');\n\n# Output:\n# New notification: { channel: 'my_notification', payload: 'User Alice updated' }\n<\/code><\/pre>\n<p>In this example, the <code>client<\/code> subscribes to a PostgreSQL notification channel named &#8216;my_notification&#8217;. When a new notification is published to this channel, the event handler logs the message to the console. This feature is particularly useful for applications requiring real-time data synchronization or notifications.<\/p>\n<p>By exploring these advanced features of &#8216;npm pg&#8217;, you&#8217;re not just managing your PostgreSQL database more efficiently; you&#8217;re also unlocking new potentials in your Node.js applications. Embrace these techniques to take your database management skills to the next level.<\/p>\n<h2>Exploring Alternatives to npm pg<\/h2>\n<h3>Sequelize: ORM Integration<\/h3>\n<p>While &#8216;npm pg&#8217; offers a direct route to PostgreSQL for Node.js applications, exploring ORM (Object-Relational Mapping) alternatives like Sequelize can provide additional layers of abstraction and convenience. Sequelize simplifies database operations by allowing you to work with objects and promises instead of SQL strings, making it an attractive option for complex projects.<\/p>\n<p>Here&#8217;s a basic Sequelize setup for comparison:<\/p>\n<pre><code class=\"language-javascript line-numbers\">const { Sequelize } = require('sequelize');\nconst sequelize = new Sequelize('postgres:\/\/dbuser:secretpassword@localhost:5432\/mydb');\n\n(async () =&gt; {\n  try {\n    await sequelize.authenticate();\n    console.log('Connection has been established successfully.');\n  } catch (error) {\n    console.error('Unable to connect to the database:', error);\n  }\n})();\n\n# Output:\n# Connection has been established successfully.\n<\/code><\/pre>\n<p>This code demonstrates how to establish a connection to a PostgreSQL database using Sequelize. The <code>sequelize.authenticate()<\/code> method is called to test the connection, and a success message is logged upon successful connection. This approach abstracts the direct database connection details, focusing instead on model interactions.<\/p>\n<h3>Pros and Cons of Sequelize vs. npm pg<\/h3>\n<p><strong>Pros of Sequelize:<\/strong><br \/>\n&#8211; <strong>Abstraction:<\/strong> Offers a higher level of abstraction, making database interactions more intuitive.<br \/>\n&#8211; <strong>ORM Features:<\/strong> Supports model definition, associations, transactions, and more, out of the box.<\/p>\n<p><strong>Cons of Sequelize:<\/strong><br \/>\n&#8211; <strong>Performance:<\/strong> The abstraction layer can introduce overhead, potentially affecting performance.<br \/>\n&#8211; <strong>Complexity:<\/strong> May be overkill for simple projects or those with specific performance requirements.<\/p>\n<h3>Making the Right Choice<\/h3>\n<p>Deciding between &#8216;npm pg&#8217; and ORM alternatives like Sequelize depends on your project&#8217;s complexity, performance needs, and your comfort level with SQL. &#8216;npm pg&#8217; provides a lean and direct approach, ideal for those who prefer working closely with SQL and need maximum performance. On the other hand, Sequelize and similar ORMs offer convenience and simplicity at the cost of some performance overhead.<\/p>\n<p>By understanding the strengths and limitations of each approach, you can make an informed decision that best suits your Node.js application&#8217;s needs. Whether you choose &#8216;npm pg&#8217; for its directness and efficiency or Sequelize for its ORM benefits, both paths lead to successful PostgreSQL integration in Node.js.<\/p>\n<h2>Troubleshooting Tips with npm pg<\/h2>\n<h3>Handling Connection Timeouts<\/h3>\n<p>One of the frequent challenges developers face when using &#8216;npm pg&#8217; involves connection timeouts. These occur when a connection to the PostgreSQL database takes too long to establish, often due to network issues or server overload.<\/p>\n<p>To mitigate this, you can configure connection timeout settings in your pool or client setup. Here&#8217;s how to set a connection timeout of 3000 milliseconds (3 seconds):<\/p>\n<pre><code class=\"language-javascript line-numbers\">const { Pool } = require('pg');\nconst pool = new Pool({\n  connectionString: 'postgres:\/\/dbuser:secretpassword@localhost:5432\/mydb',\n  connectionTimeoutMillis: 3000\n});\n\n# Output:\n# If a connection cannot be established within 3 seconds, it times out\n<\/code><\/pre>\n<p>This code snippet demonstrates adding a <code>connectionTimeoutMillis<\/code> option to your pool configuration. Adjusting this setting helps prevent your application from hanging indefinitely while trying to connect, enhancing its responsiveness and reliability.<\/p>\n<h3>Managing Disconnections Gracefully<\/h3>\n<p>Disconnections can disrupt your application&#8217;s flow, especially in long-running applications that maintain persistent connections to the database. Implementing reconnection logic is crucial for maintaining uninterrupted database interactions.<\/p>\n<p>Here&#8217;s an example of handling disconnections by listening to the &#8216;error&#8217; event on the client:<\/p>\n<pre><code class=\"language-javascript line-numbers\">const { Client } = require('pg');\nconst client = new Client();\nclient.on('error', (err) =&gt; {\n  console.error('Unexpected disconnection:', err);\n  client.connect();\n});\n\n# Output:\n# Logs any disconnection errors and attempts to reconnect\n<\/code><\/pre>\n<p>In this scenario, the <code>client.on('error', ...)<\/code> listener detects disconnections. Upon an error, it logs the issue and attempts to reconnect. This proactive approach ensures your application remains robust against unexpected database disconnections.<\/p>\n<h3>Optimizing for Large Datasets<\/h3>\n<p>Working with large datasets presents its own set of challenges, such as increased memory usage and slower query responses. To optimize performance, consider using cursors for fetching large amounts of data incrementally.<\/p>\n<pre><code class=\"language-javascript line-numbers\">const { Pool, Cursor } = require('pg');\nconst pool = new Pool();\nconst cursor = new Cursor('SELECT * FROM large_table');\nconst client = await pool.connect();\nclient.query(cursor);\n\ncursor.read(100, (err, rows) =&gt; {\n  console.log('Fetched rows:', rows);\n});\n\n# Output:\n# Fetched rows: [Array of rows, up to 100 at a time]\n<\/code><\/pre>\n<p>This example introduces the use of a <code>Cursor<\/code> to fetch data from a large table in chunks. By specifying how many rows to read at a time, you can manage memory usage more effectively and keep your application responsive.<\/p>\n<p>By addressing these common issues with strategic solutions and workarounds, you can enhance the stability and performance of your Node.js applications using &#8216;npm pg&#8217;. Embracing these practices will not only solve immediate problems but also contribute to a more resilient and efficient application architecture.<\/p>\n<h2>PostgreSQL: The Robust Database<\/h2>\n<h3>Why Choose PostgreSQL?<\/h3>\n<p>PostgreSQL stands out in the world of database systems for its reliability, robust feature set, and its open-source nature. As a powerful object-relational database system, it provides extensive data types, including JSON support, and sophisticated features like table inheritance and function overloading. These capabilities make PostgreSQL a versatile choice for a wide range of applications, from small startups to large enterprises.<\/p>\n<h3>npm pg: Bridging Node.js and PostgreSQL<\/h3>\n<p>Integrating Node.js applications with PostgreSQL is made seamless with the &#8216;npm pg&#8217; package. This Node.js module serves as a client for interfacing with your PostgreSQL database, offering both a low-level client for executing queries and a high-level pool for managing connections efficiently.<\/p>\n<p>To demonstrate the synergy between Node.js and PostgreSQL using &#8216;npm pg&#8217;, consider this example where we query the version of the PostgreSQL server:<\/p>\n<pre><code class=\"language-javascript line-numbers\">const { Client } = require('pg');\nconst client = new Client({\n  connectionString: 'postgres:\/\/dbuser:secretpassword@localhost:5432\/mydb'\n});\nclient.connect();\nclient.query('SELECT version();', (err, res) =&gt; {\n  if (err) throw err;\n  console.log(res.rows[0].version);\n});\n\n# Output:\n# PostgreSQL 13.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 9.3.0, 64-bit\n<\/code><\/pre>\n<p>This code snippet illustrates how to establish a connection to a PostgreSQL database and execute a query to retrieve the server version. The output displays the PostgreSQL version, showcasing the ability to interact directly with the database and retrieve valuable information. This example highlights the importance of &#8216;npm pg&#8217; in facilitating direct communication between Node.js applications and PostgreSQL databases, enabling developers to leverage the full power of PostgreSQL&#8217;s features within their applications.<\/p>\n<h3>Efficient Database Management with npm pg<\/h3>\n<p>Efficient database management is crucial for the performance and scalability of applications. &#8216;npm pg&#8217; plays a pivotal role in this, offering features like connection pooling and transaction management that help in optimizing database interactions. By harnessing these features, developers can ensure their applications run smoothly, even under high loads, making &#8216;npm pg&#8217; an invaluable tool for modern web development.<\/p>\n<p>Understanding the fundamentals of PostgreSQL and the capabilities of &#8216;npm pg&#8217; provides a solid foundation for developers looking to integrate these powerful technologies into their Node.js applications. With &#8216;npm pg&#8217;, harnessing the full potential of PostgreSQL becomes an achievable goal, paving the way for building robust and efficient applications.<\/p>\n<h2>Best Practices: Scaling with npm pg<\/h2>\n<h3>Integrating npm pg with Express.js<\/h3>\n<p>When building web applications with Node.js, integrating PostgreSQL using &#8216;npm pg&#8217; with frameworks like Express.js can significantly streamline development. This combination allows for the efficient handling of database operations alongside server-side logic. Here\u2019s an example of how you can integrate &#8216;npm pg&#8217; within an Express.js route to fetch data:<\/p>\n<pre><code class=\"language-javascript line-numbers\">const express = require('express');\nconst { Pool } = require('pg');\nconst app = express();\nconst pool = new Pool();\n\napp.get('\/users', async (req, res) =&gt; {\n  const { rows } = await pool.query('SELECT * FROM users');\n  res.json(rows);\n});\n\napp.listen(3000, () =&gt; console.log('App running on port 3000'));\n\n# Output:\n# App running on port 3000\n<\/code><\/pre>\n<p>In this snippet, an Express.js application is set up with a route to fetch all users from a PostgreSQL database and return them as JSON. This example illustrates the seamless integration of &#8216;npm pg&#8217; with Express.js, enabling the creation of dynamic web applications that interact with PostgreSQL databases efficiently.<\/p>\n<h3>Mastering Complex Queries and Migrations<\/h3>\n<p>As applications grow, handling complex queries and managing database schema migrations become critical. &#8216;npm pg&#8217; supports these advanced requirements, allowing developers to execute complex SQL queries and manage database changes programmatically. For migrations, tools like <code>node-pg-migrate<\/code> can be integrated with &#8216;npm pg&#8217; to automate and manage schema changes smoothly.<\/p>\n<pre><code class=\"language-javascript line-numbers\">\/\/ Example of a complex query\nconst result = await pool.query('SELECT * FROM users WHERE age &gt; $1', [25]);\nconsole.log('Users older than 25:', result.rows);\n\n# Output:\n# Users older than 25: [Array of user objects]\n<\/code><\/pre>\n<p>This code demonstrates executing a parameterized query, fetching users older than 25. It showcases &#8216;npm pg\u2019s ability to handle complex SQL queries efficiently, providing developers with the flexibility to interact with the database according to their application&#8217;s needs.<\/p>\n<h3>Further Resources for Mastering npm pg<\/h3>\n<p>To deepen your understanding of &#8216;npm pg&#8217; and PostgreSQL, consider exploring the following resources:<\/p>\n<ul>\n<li><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/www.npmjs.com\/package\/pg\" target=\"_blank\" rel=\"noopener\">PG NPM Package<\/a> &#8211; A non-blocking PostgreSQL client for Node.js.<\/p>\n<\/li>\n<li>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/www.postgresql.org\/docs\/\" target=\"_blank\" rel=\"noopener\">Official PostgreSQL Documentation<\/a> &#8211; A comprehensive guide detailing all aspects of PostgreSQL.<\/p>\n<\/li>\n<li>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/dev.to\/saint_vandora\/integrating-nodejs-with-relational-databases-a-comprehensive-guide-25ba\" target=\"_blank\" rel=\"noopener\">Integrating NodeJS with Relational Databases<\/a> &#8211; A step by step guide for integrating Node.js.<\/p>\n<\/li>\n<\/ul>\n<p>By leveraging these resources, you can elevate your skills in database management, optimization, and security. Whether you\u2019re integrating &#8216;npm pg&#8217; with Express.js, handling complex queries, or managing database migrations, these resources provide a wealth of knowledge to support your journey in building scalable and efficient Node.js applications with PostgreSQL.<\/p>\n<h2>Recap: npm pg Usage Guide<\/h2>\n<p>In this comprehensive guide, we&#8217;ve navigated the essentials of utilizing &#8216;npm pg&#8217; for PostgreSQL database management within Node.js applications. From the initial setup to leveraging advanced features, &#8216;npm pg&#8217; serves as a powerful tool for developers seeking efficient database interaction.<\/p>\n<p>We began with the basics, detailing how to install &#8216;npm pg&#8217; and establish a connection to your PostgreSQL database. We then delved into executing simple queries, highlighting the ease with which developers can interact with their databases.<\/p>\n<p>Moving to more complex scenarios, we explored connection pooling and transaction management, demonstrating &#8216;npm pg&#8217;s capabilities to handle high-demand environments effectively. We also touched on the utility of listening for PostgreSQL notifications, a feature that enriches real-time application responsiveness.<\/p>\n<p>Alternative approaches such as Sequelize were discussed, providing insights into the broader ecosystem of Node.js database management solutions. This comparison allowed us to appreciate &#8216;npm pg&#8217;s direct approach versus the abstraction offered by ORM solutions.<\/p>\n<table>\n<thead>\n<tr>\n<th>Approach<\/th>\n<th>Directness<\/th>\n<th>Performance<\/th>\n<th>Complexity<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>npm pg<\/td>\n<td>High<\/td>\n<td>Excellent<\/td>\n<td>Moderate<\/td>\n<\/tr>\n<tr>\n<td>Sequelize (ORM)<\/td>\n<td>Lower<\/td>\n<td>Good<\/td>\n<td>Higher<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Whether you&#8217;re just starting out with &#8216;npm pg&#8217; or seeking to deepen your database management skills, this guide has aimed to equip you with the knowledge to confidently manage PostgreSQL databases in your Node.js applications. The journey doesn&#8217;t end here; continuing to explore and experiment with &#8216;npm pg&#8217; and its advanced features will further enhance your capabilities.<\/p>\n<p>With its robustness and flexibility, &#8216;npm pg&#8217; stands as a testament to the powerful synergy between Node.js and PostgreSQL. Embrace these tools to build scalable, efficient, and dynamic applications. Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>At IOFlood, integrating PostgreSQL databases into our Node.js applications was a common task. Now that we have solved this challenge, we&#8217;ve created a guide to help streamline the process. By following these instructions, you&#8217;ll confidently navigate PostgreSQL integration, enabling you to build scalable applications with ease. This guide will walk you through the installation, basic [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":18909,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[125,155,121],"tags":[],"class_list":["post-18158","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","category-node-js","category-programming-coding","cat-125-id","cat-155-id","cat-121-id","has_thumb"],"_links":{"self":[{"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/posts\/18158","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/comments?post=18158"}],"version-history":[{"count":15,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/posts\/18158\/revisions"}],"predecessor-version":[{"id":19025,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/posts\/18158\/revisions\/19025"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/media\/18909"}],"wp:attachment":[{"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/media?parent=18158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/categories?post=18158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/tags?post=18158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}