<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Williams</title>
    <description>The latest articles on DEV Community by Williams (@williamsgqdev).</description>
    <link>https://dev.to/williamsgqdev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F848428%2F6ae61ec3-fc57-4397-b048-c2433f9d3f4f.jpeg</url>
      <title>DEV Community: Williams</title>
      <link>https://dev.to/williamsgqdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/williamsgqdev"/>
    <language>en</language>
    <item>
      <title>How to Connect Your Nest.js App to AWS DocumentDB: A Step-by-Step Guide</title>
      <dc:creator>Williams</dc:creator>
      <pubDate>Thu, 28 Nov 2024 22:29:16 +0000</pubDate>
      <link>https://dev.to/williamsgqdev/how-to-connect-your-nestjs-app-to-aws-documentdb-1el7</link>
      <guid>https://dev.to/williamsgqdev/how-to-connect-your-nestjs-app-to-aws-documentdb-1el7</guid>
      <description>&lt;p&gt;Setting up your NestJS application to connect with Amazon DocumentDB can be challenging. You might face issues with TLS/SSL configuration or security groups.&lt;br&gt;
This guide will walk you through the process smoothly, ensuring a hassle-free setup.&lt;/p&gt;
&lt;h2&gt;
  
  
  Understanding the Connectivity requirement of DocumentDb
&lt;/h2&gt;

&lt;p&gt;Before creating your DocumentDB database, it's important to know that Amazon DocumentDB is accessible by Amazon EC2 instances and other AWS services within the same VPC. You can connect also from different VPCs within the same AWS Region or across Regions using VPC peering.&lt;/p&gt;

&lt;p&gt;If you need to access DocumentDB from outside AWS, you can use SSH tunneling.&lt;/p&gt;
&lt;h3&gt;
  
  
  1. Creating a New Amazon DocumentDB Cluster
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Access the AWS Console&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Login to your AWS console.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the search bar at the top of the console, type "DocumentDB" and select Amazon DocumentDB from the search results.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fieymomkbragb8fm1207q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fieymomkbragb8fm1207q.png" alt="Image description" width="800" height="453"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Begin Cluster Creation&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;On the Amazon DocumentDB page, click Create Cluster or Create your first cluster if this is your first time setting up DocumentDB.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdu6nef3qlldy8rboc8up.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdu6nef3qlldy8rboc8up.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Configure Cluster Settings&lt;/strong&gt;: Fill in the required information&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;DB Cluster Identifier&lt;/strong&gt;: Provide a unique name for your cluster.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Authentication Method&lt;/strong&gt;: Enter the necessary credentials (username and password) for your cluster.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp7z3l40njj6k3myud8hr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp7z3l40njj6k3myud8hr.png" alt="Image description" width="800" height="451"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Finalize and Create the Cluster&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;After filling in the required details, review your configuration settings&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click Create Cluster to initiate the cluster creation process.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8txcrm34d61i5ne4zrxj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8txcrm34d61i5ne4zrxj.png" alt="Image description" width="800" height="452"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;AWS will take a few minutes to provision your new DocumentDB cluster. Once completed, you'll have a fully functional cluster ready for use.&lt;/p&gt;
&lt;h3&gt;
  
  
  2.  Set Up a Security Group to Allow Connectivity to the DocumentDB Cluster Within the VPC
&lt;/h3&gt;

&lt;p&gt;Next, we'll need to configure security groups to allow our Nest.js application to connect to the DocumentDB cluster within the VPC.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Create a Security Group&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In your AWS Console, Search for &lt;strong&gt;Security Groups&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw2ybrwz0znrvnyvy9ua5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw2ybrwz0znrvnyvy9ua5.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Click Create Security Group.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Provide a Name and Description for the security group &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ensure you select the appropriate VPC where your DocumentDB cluster reside&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Configure Inbound Rules&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9mvoyuufcdbdtvjtn0wz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9mvoyuufcdbdtvjtn0wz.png" alt="Image description" width="800" height="451"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Under the Inbound rules tab, click Add Rule.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set the Type to Custom TCP&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For the Port Range, enter 27017 (the default port for DocumentDB)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the Source field, specify &lt;code&gt;Anywhere&lt;/code&gt; or &lt;code&gt;0.0.0.0/0&lt;/code&gt; this would allow us to connect from anywhere within the vpc&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Configure Outbound Rules&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc674n97ar4kjoknawhhb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc674n97ar4kjoknawhhb.png" alt="Image description" width="800" height="451"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Under the Outbound rules tab, click Add Rule.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set the Type to Custom TCP&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For the Port Range, enter 27017 (the default port for DocumentDB)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the Source field, specify &lt;code&gt;Anywhere&lt;/code&gt; or &lt;code&gt;0.0.0.0/0&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once you've configured the rules, click Create Security Group. Your new security group is now ready to allow traffic to and from your DocumentDB cluster.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Modify DocumentDb Security Group&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg5twgihbl7c5xr258t43.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg5twgihbl7c5xr258t43.png" alt="Image description" width="800" height="509"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Go back to the Amazon DocumentDB service in the AWS Console&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select your newly created cluster.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;On the VPC Security groups section replace the current security group with the new one you created.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click Continue to proceed.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5vuk1c8ytsv10d2ag3xc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5vuk1c8ytsv10d2ag3xc.png" alt="Image description" width="800" height="520"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Check the Apply Immediately box to enforce the changes without delay.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click Modify cluster to finalize the update.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The above steps will update your cluster's security settings, ensuring your DocumentDB is fully configured and ready for use.&lt;/p&gt;
&lt;h3&gt;
  
  
  3. Creating Our Nest.js application and Connecting to DocumentDb
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Let's create a new NestJS project&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nest new document-db-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I would Open the project with vs code and install the necessary dependencies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install @nestjs/mongoose mongoose @nestjs/config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4: Download the Amazon DocumentDB Certificate Authority (CA) certificate&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiafellkcq6pgeb2t8lud.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiafellkcq6pgeb2t8lud.png" alt="Image description" width="800" height="212"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Navigate to your DocumentDB dashboard and click the &lt;code&gt;Connectivity &amp;amp; Security&lt;/code&gt; tab. Find and copy the &lt;a href="https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem" rel="noopener noreferrer"&gt;link&lt;/a&gt; to download the Amazon DocumentDB CA certificate. Save this file in the root of your project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5: Setup Connection to Document db&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//src/app.module.ts

import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { MongooseModule } from '@nestjs/mongoose';
import * as path from 'path';

@Module({
  imports: [
    ConfigModule.forRoot(),
    MongooseModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) =&amp;gt; ({
        uri: configService.get('DOCUMENTDB_URI'),
        tls: true,
        tlsCAFile: path.resolve('global-bundle.pem'),
      }),
      inject: [ConfigService],
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the app.module.ts file, we connect our NestJS application to DocumentDB using MongooseModule. Inside MongooseModule, we call the forRootAsync method to configure the connection asynchronously.&lt;/p&gt;

&lt;p&gt;In forRootAsync, we define a useFactory function, which retrieves the database URI from environment variables using &lt;code&gt;Config Module&lt;/code&gt;. We also set &lt;code&gt;tls: true&lt;/code&gt; option to enable secure communication and specify the &lt;code&gt;tlsCAFile&lt;/code&gt; option to point to our downloaded CA certificate &lt;code&gt;global-bundle.pem&lt;/code&gt;, ensuring that the connection is authenticated.&lt;/p&gt;

&lt;p&gt;By doing this, we set up a secure and reliable connection to DocumentDB, allowing our NestJS application to interact with the database safely.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6: Setting Up the Environment Variables&lt;/strong&gt;&lt;br&gt;
Create a &lt;code&gt;.env&lt;/code&gt; file in the project root and add the DocumentDb connection string&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DOCUMENTDB_URI=mongodb://username:password@&amp;lt;your-documentdb-endpoint&amp;gt;:27017/&amp;lt;your-database-name&amp;gt;?tls=true&amp;amp;replicaSet=rs0&amp;amp;readPreference=secondaryPreferred&amp;amp;retryWrites=false

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: &lt;em&gt;The above setup assumes you have your app running in the same VPC as your Documentdb cluster. Amazon DocumentDB does not support direct connections from outside the VPC for security reasons.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you need to connect from your local machine for testing or development purposes you need to setup ssh tunneling through an EC2 instance. For a step-by-step guide on how to set this up, refer to this article on &lt;a href="https://docs.aws.amazon.com/documentdb/latest/developerguide/connect-from-outside-a-vpc.html" rel="noopener noreferrer"&gt;Connecting to DocumentDB via SSH tunneling&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>nestjs</category>
      <category>database</category>
      <category>mongodb</category>
      <category>aws</category>
    </item>
    <item>
      <title>Step-by-Step Guide to Implementing Node.js Audit Trail</title>
      <dc:creator>Williams</dc:creator>
      <pubDate>Thu, 04 Jan 2024 16:11:29 +0000</pubDate>
      <link>https://dev.to/williamsgqdev/step-by-step-guide-to-implementing-nodejs-audit-trail-jic</link>
      <guid>https://dev.to/williamsgqdev/step-by-step-guide-to-implementing-nodejs-audit-trail-jic</guid>
      <description>&lt;p&gt;When developing applications, both user experience and security is paramount . One challenge is allowing users with different levels of access to use the system smoothly while also keeping a detailed record of their actions. This becomes particularly tricky when we want to track every move users make for accountability and security reasons. That's where audit trailing comes in – it's like a logbook of events that happen in our application, covering things like data changes, how the application responds, and which users are involved. It's basically our way of keeping tabs on everything that happens in the application. Lets take a look at how we can solve this challenge building our own application&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;p&gt;Let's begin our project by initializing a new Node.js application and configure typescript.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init -y &amp;amp;&amp;amp; tsc --init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, let's install the necessary dependencies including &lt;code&gt;express&lt;/code&gt;, &lt;code&gt;typescript&lt;/code&gt;, &lt;code&gt;nodemon&lt;/code&gt;, &lt;code&gt;ts-node&lt;/code&gt; and &lt;code&gt;@types/express&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i express &amp;amp;&amp;amp; npm i typescript @types/express nodemon ts-node -D
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's edit our package.json file to add our start script .&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  "scripts": {
    "start": "nodemon src/index.ts"
  },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a &lt;code&gt;src&lt;/code&gt; directory and add an &lt;code&gt;index.ts&lt;/code&gt; file to kick off our application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//src/index.ts
import express, { Request, Response } from 'express';
const app = express();

app.get('/', (req: Request, res: Response)=&amp;gt; {
    try {
        return res.status(200).json({
            msg: 'Success'
        })
    } catch (error) {
        return res.status(500).json({
            msg: 'Something went wrong, Try again !'
        })
    }
});

app.listen(5000, ()=&amp;gt; {
    console.log('App is running')
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have successfully laid the foundation for our Express application, let's proceed to create a middleware function for robust audit logging. This middleware will seamlessly track every incoming request and the corresponding response, providing a comprehensive audit trail for accountability and security.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//src/audit-log.middleware.ts

import { NextFunction, Request, Response } from "express";

export const auditLoggerInterceptResponse = async (req: Request, res: Response, next: NextFunction) =&amp;gt; {

    //Save the initial res.json method to a variable for later use
    const originalJson = res.json;

    //Overide the res.json method with a custom implementation
    res.json = function (body: any) {

         // Create a payload capturing relevant information about the request and response
            const payload = {
                url: req.originalUrl,
                method: req.method,
                body: req.body,
                params: req.params,
                headers: req.headers,
                statusCode: res.statusCode,
                response: body,
            };


            console.log(payload);

        //Save Payload
        /* 
            Implement database logic
            Note: Make use of Promise chaining for promises . Using async await
            would not match the return type of res.json. This may result in an error
        */

        // Call the original `res.json` method to send the response
        return originalJson.call(this, body);
    };

    // Move to the next middleware or route handler in the Express middleware stack
    next();
};

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let me break down how this function works&lt;/p&gt;

&lt;p&gt;1 . Save the Initial res.json Method:&lt;/p&gt;

&lt;p&gt;const &lt;code&gt;originalJson = res.json;&lt;/code&gt;&lt;br&gt;
The original res.json method is saved to the variable &lt;code&gt;originalJson&lt;/code&gt; for later use.&lt;/p&gt;

&lt;p&gt;2 . Override res.json with Custom Implementation:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;res.json = function (body: any) {...};&lt;/code&gt;&lt;br&gt;
The res.json method is overridden with a custom implementation inside the middleware.&lt;br&gt;
This custom implementation captures relevant information about the incoming request (req) and the outgoing response (res).&lt;br&gt;
It creates a payload object containing details such as the request URL, method, body, parameters, headers, response status code, and response body.&lt;/p&gt;

&lt;p&gt;3 . Database Logic Reminder:&lt;/p&gt;

&lt;p&gt;A comment reminds developers to implement database logic for saving the payload.&lt;br&gt;
It suggests using Promise chaining for promises, as using async/await might not match the return type of res.json.&lt;/p&gt;

&lt;p&gt;** Note: For simplicity, the implementation above omits the database logic section. In a real-world scenario, you would have to integrate your preferred database logic within the designated section to ensure a tailored and robust audit trail for your application **&lt;/p&gt;

&lt;p&gt;4 . Call the Original res.json Method:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;return originalJson.call(this, body);&lt;/code&gt;&lt;br&gt;
The original res.json method is called to ensure that the response is sent to the client as intended.&lt;/p&gt;

&lt;p&gt;5 . Move to the Next Middleware or Route Handler:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;next();&lt;/code&gt;&lt;br&gt;
The next() function is called to move to the next middleware or route handler in the Express middleware stack.&lt;/p&gt;

&lt;p&gt;In a nutshell this middleware modifies the res.json function so that when called in our routes it would perform our custom implementation. This tweak acts as a potent tool for improving our application's audit trail, incorporating custom actions during the response phase.&lt;/p&gt;

&lt;p&gt;Let's proceed to call our middleware in our &lt;code&gt;index.ts&lt;/code&gt; as a global middleware&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//src/index.ts

import express, { Request, Response } from 'express';
import { auditLoggerInterceptResponse } from './audit-log.middleware';
const app = express();

app.use(auditLoggerInterceptResponse);

app.get('/', (req: Request, res: Response)=&amp;gt; {
    try {
        return res.status(200).json({
            msg: 'Success'
        })
    } catch (error) {
        return res.status(500).json({
            msg: 'Something went wrong, Try again !'
        })
    }
});

app.listen(5000, ()=&amp;gt; {
    console.log('App is running')
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Concluding our exploration, making a request to the GET route reveals the middleware function's response in our console, showcasing the powerful audit logging capabilities we've integrated. This hands-on experience solidifies the significance of our middleware as a crucial tool for observing user interactions, ultimately bolstering security and accountability within our Node.js application.&lt;/p&gt;

&lt;p&gt;Github Repository: &lt;a href="https://github.com/williamsgqdev/AuditLog-Ts"&gt;Repository Link&lt;/a&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Worker Threads Nodejs</title>
      <dc:creator>Williams</dc:creator>
      <pubDate>Fri, 07 Jul 2023 10:43:36 +0000</pubDate>
      <link>https://dev.to/williamsgqdev/worker-threads-nodejs-2na2</link>
      <guid>https://dev.to/williamsgqdev/worker-threads-nodejs-2na2</guid>
      <description>&lt;p&gt;The worker thread module in Node.js allows us to run JavaScript code in parallel, preventing CPU-intensive operations from blocking the main thread of our application. Before delving deeper into this module, it's important to understand a few key concepts. Familiarity with these concepts will help us use and benefit from worker threads effectively.&lt;/p&gt;

&lt;h2&gt;
  
  
  CPU Core
&lt;/h2&gt;

&lt;p&gt;A CPU core serves as the fundamental unit responsible for executing instructions within a computer system. When exploring computing systems, it is essential to distinguish between single-core and multi-core systems. In a multi-core system, there are multiple CPU cores available, each capable of independent execution. Worker threads in Node.js can be distributed across multiple CPU cores to achieve parallel execution and leverage the full processing power of the system.&lt;/p&gt;

&lt;p&gt;In contrast, a single-core system has only one CPU core available for executing instructions. When worker threads are introduced in such a system, they run alongside the main thread but do not achieve true parallelism. Instead, a technique called time-sharing is used. This means that when a worker thread is scheduled to run, it occupies the sole CPU core, causing the main thread and other threads to wait until the core becomes available again. As a result, the main thread gets blocked, leading to decreased application performance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Threads
&lt;/h2&gt;

&lt;p&gt;Threads play a vital role in dividing the execution of a program into concurrent tasks, enabling both concurrency and parallelism. Essentially, threads serve as the smallest units of execution within a program. However, Node.js, which is primarily single-threaded, introduces the concept of threads through the underlying libuv library. This powerful library handles asynchronous I/O operations and manages the event loop efficiently. It achieves this by utilizing a dynamic thread pool that adapts based on system conditions and configurations.&lt;/p&gt;

&lt;p&gt;On the other hand, the V8 engine, responsible for executing JavaScript code in Node.js, employs multiple threads internally for tasks like garbage collection and other optimizations. These threads are managed by the V8 engine itself and are not directly exposed or configurable within Node.js. Overall, the combined use of threads, the libuv library, and the V8 engine enables Node.js to handle concurrent and parallel tasks effectively, enhancing performance and responsiveness.&lt;/p&gt;

&lt;h2&gt;
  
  
  Worker Thread
&lt;/h2&gt;

&lt;p&gt;We have covered the fundamental concepts . Now, we can proceed to learning how to utilize worker threads in our applications.&lt;/p&gt;

&lt;p&gt;To initialize a new Node.js application, run the following command to generate a package.json file with default settings:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default, Node.js comes bundled with the worker thread module. To create a simple server, let's install Express&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i express
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In our package.json we can go ahead and create a start script&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//package.json

"scripts": {
  "start": "node index.js"
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your updated package.json file should look like this 👇👇&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F616mux58pax8gm0tf7xx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F616mux58pax8gm0tf7xx.png" alt="Image description" width="800" height="770"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let's create a simple program that simulates blocking the main thread. This program will loop one million times and write its output to a file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//index.js

const fs = require('node:fs');
const express = require('express');
const app = express();

app.get('/write', async (req, res) =&amp;gt; {
     try {
        for(let i = 0; i &amp;lt; 1000000 ; i++){
            fs.appendFileSync( 'test.txt',` ${i} `);

        }
        return res.status(200).json("Done");
     } catch (error) {
        return res.status(500).json("Error Occured ");
     }
});

app.get('/' , (req , res)=&amp;gt; {
    try {
        return res.status(200).json("Health check route");
    } catch (error) {
        return res.status(500).json("Error Occured ");
    }
})

app.listen(3001 , ()=&amp;gt; {
    console.log(" App is running in 3001 ");
});

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code inside the /write route will block the main thread when executed. This means it will consume all available resources, preventing other incoming requests from being processed.&lt;/p&gt;

&lt;p&gt;To fix this issue and avoid blocking the main thread , we can utilize the worker thread .&lt;/p&gt;

&lt;p&gt;Let's modify our code to use the worker thread . Let's create a separate file called 'worker.js'&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//worker.js

const fs = require('fs');
const { parentPort } = require('worker_threads');
const {
    workerData
} = require("worker_threads");

const count = workerData

for(let i = 0; i &amp;lt; count ; i++){
    fs.appendFileSync( 'test.txt',` ${i} `);
}

parentPort.postMessage(`Done`)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In the worker.js file, we import the required modules fs, parentPort, and workerData from the worker_threads module.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The workerData variable allows passing data from the main thread to the worker thread. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Inside the worker thread, we perform the expensive operation, which in this case is appending a sequence of numbers to the test.txt file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After the operation is completed, we use parentPort.postMessage() to send a message back to the main thread, indicating that the task is done.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can now proceed to modify our index.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//index.js

const express = require('express');
const app = express();
const {Worker} = require('worker_threads');

app.get('/write', async (req, res) =&amp;gt; {
     try {
      const worker = new Worker('./worker.js' , {workerData : 1000000});
      worker.on("message", msg =&amp;gt; {
        return  res.status(200).json(msg);
      });
      worker.on("error", err =&amp;gt; console.error(err));

     } catch (error) {
        console.log(error);
        return res.status(500).json("Error Occured ");
     }
});

app.get('/' , (req , res)=&amp;gt; {
    try {
        return res.status(200).json("Health check route");
    } catch (error) {
        return res.status(500).json("Error Occured ");
    }
})

app.listen(3001 , ()=&amp;gt; {
    console.log(" App is running in 3001 ");
});

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In the updated index.js file , When a GET request is made to the &lt;code&gt;/write&lt;/code&gt; route a new worker thread is created using the Worker class from the &lt;code&gt;worker_threads&lt;/code&gt; module&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;workerData&lt;/code&gt; option is used to pass the value 1000000 to the worker thread. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Two event listeners, message and error, are added to the worker thread. The message listener handles messages sent from the worker thread, while the error listener handles any errors that occur.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With this implementation, the /write route will spawn a worker thread to execute the blocking loop. The main thread remains responsive to handle other incoming requests, improving the overall performance and responsiveness of the application.&lt;/p&gt;

</description>
      <category>node</category>
      <category>backend</category>
      <category>typescript</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How to publish your own npm package - Typescript</title>
      <dc:creator>Williams</dc:creator>
      <pubDate>Sat, 04 Mar 2023 23:34:37 +0000</pubDate>
      <link>https://dev.to/williamsgqdev/building-and-publish-npm-package-typescript-1cie</link>
      <guid>https://dev.to/williamsgqdev/building-and-publish-npm-package-typescript-1cie</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;NPM (Node Package Manager) is a popular JavaScript package manager. It is one of the largest software registries with over a million packages. It is an excellent way for developers to share reusable code with other developers. This article will explain how to write and publish an NPM package. We will be using &lt;a href="https://tsdx.io/#quick-start" rel="noopener noreferrer"&gt;TSDX&lt;/a&gt; to bootstrap our package. &lt;a href="https://tsdx.io/#quick-start" rel="noopener noreferrer"&gt;TSDX&lt;/a&gt; is a zero-config CLI that helps you develop, test, and publish modern TypeScript packages with ease.&lt;/p&gt;

&lt;h3&gt;
  
  
  Initialize Our Package
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx tsdx create &amp;lt;Your project name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;select basic and continue&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmndu5soj2d1dw1g192uz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmndu5soj2d1dw1g192uz.png" alt="Tsdx template selection screen" width="800" height="274"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Let's write our package
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// src/index.ts

class MyInfo {

  name: string;
  age: number;

  constructor(name: string, age: number) {
    this.name = name;
    this.age = age;
  }

  myName() {
    return `Hi there my name is ${this.name}`
  }

  myAge() {
    return `I am ${this.age} years old`
  }

  yearOfBirth() {
    return 2023 - this.age
  }

}

export default MyInfo

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a simple package that takes in the name and age when you create a new instance of the class &lt;code&gt;MyInfo&lt;/code&gt;, The instance would have the functions in the class (myName, myAge, yearOfBirth).&lt;/p&gt;

&lt;p&gt;We can go ahead and publish our package, Let's go ahead and publish locally for testing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Publish locally

npm link
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can now make use of the above created package in our projects locally&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Make use of the package locally

npm link &amp;lt;Your project name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import MyInfo from 'Your Project name'

const myInfo = new MyInfo('Williams' , 10);

console.log(myInfo.myName()); // output: "Hi there my name is Williams"
console.log(myInfo.myAge()); // output: "I am 10 years old"
console.log(myInfo.yearOfBirth()); // output: 2013

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Publish to the NPM Registry
&lt;/h2&gt;

&lt;p&gt;Now that we have our package written and tested locally, we can publish it to the NPM registry for others to use.&lt;/p&gt;

&lt;p&gt;First, you'll need to create an account on the NPM website if you don't already have one. Once you've done that, you can log in to your account from the command line using the npm login command. This will prompt you for your NPM username and password.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm login

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, navigate to the root directory of your project and run the npm publish command. This will package up your code and upload it to the NPM registry.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm publish
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Congratulations! Your package is now published on the NPM registry and is available for others to use. They can install it in their own projects using the npm install  command.&lt;/p&gt;

&lt;p&gt;In this article, we've learned how to write and publish an NPM package using TSDX. We've covered how to create a new project, write some code, and publish the package to the NPM registry. With these tools and techniques, you can share your own reusable code with others.&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Introduction to Node.js Buffer Module</title>
      <dc:creator>Williams</dc:creator>
      <pubDate>Mon, 13 Feb 2023 11:16:52 +0000</pubDate>
      <link>https://dev.to/williamsgqdev/introduction-to-nodejs-buffer-module-i9f</link>
      <guid>https://dev.to/williamsgqdev/introduction-to-nodejs-buffer-module-i9f</guid>
      <description>&lt;h2&gt;
  
  
  Introduction?
&lt;/h2&gt;

&lt;p&gt;The Buffer module in Node.js is a way to handle binary data. In order to understand the Buffer module, we first need to have a good understanding of binary data and character sets.&lt;/p&gt;

&lt;h2&gt;
  
  
  Binary Data
&lt;/h2&gt;

&lt;p&gt;Binary data is data that can only take on two possible states, which are 0 and 1. This is the language that computers understand, and all your images, videos, and text are stored as binary data in the form of 0s and 1s at the core of your computer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Character Sets
&lt;/h2&gt;

&lt;p&gt;A character set, also known as an encoding system, is a system that lets computers know how to recognize characters such as letters, numbers, punctuation marks, and whitespace. The Unicode character set is a widely used encoding system, where characters have decimal representations that are then converted into binary numbers that computers can understand. You can find all the Unicode characters and their decimal, binary, and hexadecimal representation at &lt;a href="https://unicodelookup.com/" rel="noopener noreferrer"&gt;https://unicodelookup.com/&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let's dive right into the Node.js Buffer module, we now have a clear understanding of what binary data are and character sets are . We would covering just a few methods to give us the basic understanding of this module&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Buffer } from 'buffer'

const buf1 = Buffer.alloc(10);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In example above we created an empty buffer container with the length  of 10 (10 byte of data) . We can then write to this buffer container using the write method&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;buf1.write('Hello' , 'utf-8')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the write method takes in two arguments , the first is a string and the second is the encoding type . the written byte ('Hello') cannot exceed the length (in bytes) of the buffer container buf1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Buffer } from 'buffer'

const buf2 = Buffer.from('string' , 'utf-8');

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even better We can create a buffer filled with the specified string, array, or buffer using the Buffer.from() method. The size of the buffer, in bytes, is determined by the length of the data passed as the first argument&lt;/p&gt;

&lt;p&gt;Let Convert the above created buffer back to string&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(buf2.toString());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, the buffer buf2 was created from a string using the Buffer.from() method. The buf2.toString() method was then called to convert the binary data in the buffer back into a string, which was logged to the console.&lt;/p&gt;

&lt;p&gt;The encoding type argument is optional, and if not specified, the default encoding of 'utf-8' is used. Other supported encoding types include 'ascii', 'utf16le', 'ucs2', 'base64', 'latin1', and 'binary'.&lt;/p&gt;

&lt;p&gt;In addition to the methods covered in this article, there are many more available in the Buffer module. For a full list of all the methods and more in-depth explanations, you can visit the official Node.js documentation at &lt;a href="https://nodejs.org/api/buffer.html" rel="noopener noreferrer"&gt;https://nodejs.org/api/buffer.html&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The purpose of this article was to provide a comprehensive overview of the Buffer module in Node.js, and give you a solid understanding of how it works. Whether you are a beginner or an experienced developer, understanding the Buffer module is an important aspect of working with binary data in Node.js. With the knowledge gained from this article, you now have a foundation to build upon and explore the full range of capabilities offered by the Buffer module.&lt;/p&gt;

</description>
      <category>announcement</category>
      <category>devto</category>
      <category>web3</category>
      <category>community</category>
    </item>
  </channel>
</rss>
