<?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: Caleb Nkunze</title>
    <description>The latest articles on DEV Community by Caleb Nkunze (@cank256).</description>
    <link>https://dev.to/cank256</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%2F191790%2F13731f56-8019-46b1-8b6d-a37682e1e4dc.png</url>
      <title>DEV Community: Caleb Nkunze</title>
      <link>https://dev.to/cank256</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cank256"/>
    <language>en</language>
    <item>
      <title>MarketMail</title>
      <dc:creator>Caleb Nkunze</dc:creator>
      <pubDate>Tue, 27 May 2025 21:37:12 +0000</pubDate>
      <link>https://dev.to/cank256/marketmail-1hl4</link>
      <guid>https://dev.to/cank256/marketmail-1hl4</guid>
      <description>&lt;p&gt;This is a submission for the &lt;a href="https://dev.to/challenges/postmark"&gt;Postmark Challenge: Inbox Innovators&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Built 🚀
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;MarketMail&lt;/strong&gt; – a crowdsourced produce‑price exchange for Uganda &amp;amp; East Africa that runs entirely by e‑mail.&lt;br&gt;&lt;br&gt;
Farmers or enumerators send a simple price list to &lt;code&gt;prices@your-domain.com&lt;/code&gt;; Postmark’s inbound webhook feeds the data into a Node.js API, which:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Parses and validates the e‑mail (body or CSV/XLSX attachment).
&lt;/li&gt;
&lt;li&gt;Normalises units/currency and stores records in MongoDB.
&lt;/li&gt;
&lt;li&gt;Calculates daily deltas and 7‑day averages.
&lt;/li&gt;
&lt;li&gt;Sends the sender an automated market‑trend report.
&lt;/li&gt;
&lt;li&gt;Publishes an open JSON API and a React dashboard so anyone can view live prices.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The flow works from any basic e‑mail client, so even users on feature phones with intermittent data can contribute and benefit.&lt;/p&gt;
&lt;h2&gt;
  
  
  Demo 📹
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Live URL:&lt;/strong&gt; &lt;a href="https://marketmail.vercel.app" rel="noopener noreferrer"&gt;https://marketmail.vercel.app&lt;/a&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Test:&lt;/strong&gt; e‑mail the sample below to &lt;code&gt;send@marketmail.canktech.com&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;Country: Uganda
Market: Nakasero
Date: 2025‑05‑28
Maize (kg): 1850
Beans (kg): 2950
Tomatoes (crate): 9800
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’ll receive a reply within ~10 s containing a cleaned table and a mini market report. The dashboard at &lt;code&gt;https://marketmail.vercel.app/dashboard?market=Nakasero&lt;/code&gt; will update automatically.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code Repository 🗄️
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/Cank256/market-mail" rel="noopener noreferrer"&gt;https://github.com/Cank256/market-mail&lt;/a&gt;  &lt;em&gt;(MIT licence)&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How I Built It 🔧
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Email layer:&lt;/strong&gt; Postmark inbound/outbound (signature verification, bounce hooks).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Backend:&lt;/strong&gt; Node.js 20, Express, TypeScript, Zod validation.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Parsing:&lt;/strong&gt; RegEx + optional OpenAI for fuzzy headers; &lt;code&gt;papaparse&lt;/code&gt; / &lt;code&gt;xlsx&lt;/code&gt; for attachments.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data:&lt;/strong&gt; MongoDB Atlas (&lt;code&gt;MarketPrice&lt;/code&gt; schema, aggregation pipelines).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Front‑end:&lt;/strong&gt; React 18 + Vite, Recharts, Tailwind CSS + shadcn/ui.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CI/CD:&lt;/strong&gt; GitHub Actions → Vercel.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Accessibility:&lt;/strong&gt; Plain‑text fallbacks, semantic HTML, dashboard passes WCAG 2.1 AA.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dev‑experience:&lt;/strong&gt; Detailed &lt;code&gt;PROJECT.md&lt;/code&gt;, Jest tests cover parser &amp;amp; API routes.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Team:&lt;/strong&gt; solo submission — Caleb Nkunze &lt;strong&gt;&lt;a class="mentioned-user" href="https://dev.to/cank256"&gt;@cank256&lt;/a&gt;&lt;/strong&gt;. &lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>devchallenge</category>
      <category>postmarkchallenge</category>
      <category>webdev</category>
      <category>api</category>
    </item>
    <item>
      <title>Exploring Flix256: A Journey into Multimedia Content Discovery</title>
      <dc:creator>Caleb Nkunze</dc:creator>
      <pubDate>Tue, 20 Feb 2024 16:35:41 +0000</pubDate>
      <link>https://dev.to/cank256/exploring-flix256-a-journey-into-multimedia-content-discovery-mck</link>
      <guid>https://dev.to/cank256/exploring-flix256-a-journey-into-multimedia-content-discovery-mck</guid>
      <description>&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%2Fqfohjqz0x9kh2ziiyi85.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%2Fqfohjqz0x9kh2ziiyi85.png" width="800" height="360"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Screenshot of Flix256 homepage header&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;Flix256 is an innovative platform designed to revolutionize the way users explore and engage with multimedia content, including movies and TV shows. Over the course of a few weeks, I meticulously crafted Flix256 with the goal of providing users with an intuitive and immersive entertainment experience. The project targets movie enthusiasts, TV show aficionados, and anyone seeking quality entertainment options.&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%2Fy2iktjh4ekj8ycmfukzt.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%2Fy2iktjh4ekj8ycmfukzt.png" width="512" height="512"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  A Personal Connection to Flix256
&lt;/h3&gt;

&lt;p&gt;My wife would always want me to search and update her of the upcoming, new and popular movies and TV shows (believe me it was one of my superpowers that I would put in play). That coupled with my personal desire for the same desire to always be updated of the great moving pictures that studios around the world had to offer ignited my interest in creating a platform like Flix256, where users can discover and enjoy captivating content effortlessly. My journey from avid viewer to project contributor has been shaped by a deep appreciation for the transformative power of multimedia entertainment.&lt;/p&gt;

&lt;h3&gt;
  
  
  Project Accomplishments
&lt;/h3&gt;

&lt;p&gt;Flix256 boasts a robust architecture designed to streamline content discovery and enhance user engagement.&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%2Fwgejtkqydvidrxmys31d.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%2Fwgejtkqydvidrxmys31d.png" width="800" height="295"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Flix256 Architecture&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Leveraging cutting-edge technologies such as Vue.js for frontend development and Flask for backend operations, the platform delivers a seamless browsing experience across devices. Key features include personalized recommendations, advanced search functionality, and interactive user profiles. My commitment to innovation and user-centric design sets Flix256 apart as a premier destination for multimedia enthusiasts.&lt;/p&gt;

&lt;h3&gt;
  
  
  Technical Challenges
&lt;/h3&gt;

&lt;p&gt;One of the most exhilarating aspects of this project’s journey was navigating the integration of Flask and Nuxt.js, two powerful technologies that form the backbone of our application. Flask, with its flexibility and robustness in backend development, presented mewith a myriad of opportunities to build scalable and efficient APIs to handle various functionalities. On the other hand, delving into the world of Nuxt.js for frontend development introduced me to a plethora of modern JavaScript concepts and Vue.js magic, enriching my understanding of client-side rendering and state management (Pinia).&lt;/p&gt;

&lt;p&gt;However, the real test came with the deployment phase, where I aimed to deploy Flask on Heroku for backend hosting and Nuxt.js on Netlify for frontend deployment. While both platforms offer seamless deployment experiences, configuring each to work harmoniously with our specific tech stack posed a formidable challenge. I encountered hurdles in setting up environment variables, managing dependencies, and ensuring smooth integration between the backend and frontend layers.&lt;/p&gt;

&lt;p&gt;Despite the complexities, I approached each challenge with determination. Through meticulous troubleshooting, strategic collaboration, and leveraging online resources and community support, I successfully overcame these obstacles and achieved a seamless deployment of the Flask backend on Heroku and Nuxt.js frontend on Netlify. This experience not only enriched my technical acumen but also reinforced the importance of adaptability and resilience in navigating the ever-evolving landscape of web development.&lt;/p&gt;

&lt;h3&gt;
  
  
  Lessons Learned and Future Endeavors
&lt;/h3&gt;

&lt;p&gt;Through the development of Flix256, I gained invaluable insights into frontend development, backend operations, and project management. Looking ahead, I aspire to further refine my technical skills and explore emerging technologies to drive innovation in the field of multimedia content discovery. This project has reaffirmed my passion for creating impactful solutions that resonate with users and elevate their digital experiences.&lt;/p&gt;

&lt;h3&gt;
  
  
  About Me
&lt;/h3&gt;

&lt;p&gt;I am Nkunze Caleb, a dedicated software engineer with a passion for leveraging technology to solve real-world challenges. My GitHub profile showcases my contributions to various projects, including Flix256. Feel free to explore the deployed project page and visit our landing page to experience Flix256 firsthand. Let’s connect on LinkedIn to explore potential collaborations and share insights into the ever-evolving world of software development.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GitHub: &lt;a href="https://github.com/Cank256" rel="noopener noreferrer"&gt;Link to GitHub&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Deployed Project: &lt;a href="https://flix256.netlify.com" rel="noopener noreferrer"&gt;Flix256 — Explore Now&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Landing Page: &lt;a href="https://flix256-landing.netlify.com" rel="noopener noreferrer"&gt;Discover Flix256&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;LinkedIn: &lt;a href="https://www.linkedin.com/in/nkunzecaleb/" rel="noopener noreferrer"&gt;Connect on LinkedIn&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thank you for joining me on this journey through Flix256, your spot for movies and TV shows!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>The Day the Web Stood Still: A Firewall Configuration Catastrophe</title>
      <dc:creator>Caleb Nkunze</dc:creator>
      <pubDate>Wed, 17 Jan 2024 17:56:41 +0000</pubDate>
      <link>https://dev.to/cank256/the-day-the-web-stood-still-a-firewall-configuration-catastrophe-24i8</link>
      <guid>https://dev.to/cank256/the-day-the-web-stood-still-a-firewall-configuration-catastrophe-24i8</guid>
      <description>&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%2F7q5hdnqccclwtelmjrr7.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%2F7q5hdnqccclwtelmjrr7.png" width="800" height="457"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;World Wide Where (thanks to DALL-E)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;“Welcome to the &lt;strong&gt;Great Firewall Fiasco of 2024&lt;/strong&gt; , where our beloved website transformed from the ‘World Wide Web’ into the ‘World Wide Where?’. On a seemingly ordinary Tuesday morning — or as we now refer to it, ‘The Day of Digital Silence’ — our team found itself in an unexpected game of digital hide-and-seek with our own website. The culprit? A mischievous firewall rule that decided to play the overzealous bouncer, turning away all the Internet traffic like unwanted party crashers.&lt;/p&gt;

&lt;p&gt;Imagine this: One minute, you’re sipping your artisan coffee, basking in the glow of your smoothly running website. The next minute, you’re staring into the abyss of a 500 error, wondering if the Internet gods have forsaken you. Yes, folks, we had successfully turned our website into the world’s most exclusive online club — so exclusive that no one could get in, not even ourselves!&lt;/p&gt;

&lt;p&gt;Join me on this epic tale of confusion, revelation, and redemption as we unravel the mystery behind the digital blackout that left 70% of our users pondering if our website had taken an impromptu vacation. Spoiler alert: It involves a firewall rule with a mind of its own and a team of IT detectives who’ve watched one too many episodes of ‘Sherlock’.”&lt;/p&gt;

&lt;h4&gt;
  
  
  Issue Summary
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Outage Duration:&lt;/strong&gt; January 10, 2024, 10:00 AM — 11:30 AM UTC&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Impact:&lt;/strong&gt; The main website was down, resulting in a complete service outage. Approximately 70% of our users were unable to access our services.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Root Cause:&lt;/strong&gt; A misconfigured firewall rule blocked incoming traffic to the web server.&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%2Fi6zyst7ikswzitge1bj9.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%2Fi6zyst7ikswzitge1bj9.png" width="800" height="457"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Firewall Stop (Thanks to DALL-E)&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Timeline
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;10:00 AM:&lt;/strong&gt; Issue detected by our monitoring system alert.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;10:05 AM:&lt;/strong&gt; Initial investigation by the IT team suggested a server overload.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;10:20 AM:&lt;/strong&gt; Further analysis revealed normal server loads and memory usage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;10:35 AM:&lt;/strong&gt; Customer support reported multiple user complaints.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;10:50 AM:&lt;/strong&gt; Network team joined the investigation, suspecting network issues.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;11:00 AM:&lt;/strong&gt; Discovered a recent firewall rule update was incorrectly applied.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;11:15 AM:&lt;/strong&gt; Firewall rule corrected to allow web traffic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;11:30 AM:&lt;/strong&gt; Service fully restored; monitoring confirmed.&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%2F7q30gju0kawap7fvc48n.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%2F7q30gju0kawap7fvc48n.png" width="800" height="457"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;I.T Team work (Thanks to DALL-E)&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Root Cause and Resolution
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Root Cause:&lt;/strong&gt; The outage was caused by a new firewall rule that inadvertently blocked incoming HTTP and HTTPS traffic to our web server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resolution:&lt;/strong&gt; The firewall rule was corrected to allow traffic on ports 80 and 443, restoring normal service.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Corrective and Preventative Measures
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Improvements:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Implement a review process for all firewall rule changes.&lt;/li&gt;
&lt;li&gt;Enhance monitoring to include network-level checks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Task 1: Update the firewall management procedure to require peer review.&lt;/li&gt;
&lt;li&gt;Task 2: Configure additional network traffic monitoring on firewall.&lt;/li&gt;
&lt;li&gt;Task 3: Conduct a team training session on network security best practices.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the end, our computer whizzes fixed the grumpy firewall with some quick finger-tapping and teamwork. The internet started working again, and all the little data bits went zooming through happily. It just goes to show, a few laughs and some good friends make even the biggest computer boo-boos better!&lt;/p&gt;

</description>
      <category>firewall</category>
      <category>web</category>
      <category>servers</category>
      <category>postmortem</category>
    </item>
    <item>
      <title>NodeJS Gateway — Part 4: Controllers Take the Stage!</title>
      <dc:creator>Caleb Nkunze</dc:creator>
      <pubDate>Fri, 15 Dec 2023 18:09:51 +0000</pubDate>
      <link>https://dev.to/cank256/nodejs-gateway-part-4-controllers-take-the-stage-2g3f</link>
      <guid>https://dev.to/cank256/nodejs-gateway-part-4-controllers-take-the-stage-2g3f</guid>
      <description>&lt;h3&gt;
  
  
  NodeJS Gateway — Part 4: Controllers Take the Stage!
&lt;/h3&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%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F0%2A8YyFFfKwJI6hVPcV" 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%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F0%2A8YyFFfKwJI6hVPcV" width="1024" height="683"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Photo by Isis França on Unsplash&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In our previous posts, we’ve built a solid foundation for our payment gateway using JavaScript and NodeJS. We set up the gateway itself, established communication with MongoDB, and even created routes and middleware to handle requests. Now, it’s time to introduce the superstars of the show — controllers!&lt;/p&gt;

&lt;p&gt;Imagine controllers as the conductors of our payment gateway orchestra. They receive instructions from the routes, interpret them, and delegate tasks to other parts of the system like models and services. In essence, they handle the business logic of our application, keeping the routes clean and focused on traffic management.&lt;/p&gt;

&lt;p&gt;So, what can controllers do? Let’s take a look:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Process payment requests: When a user initiates a payment through the “collect” endpoint, the controller receives the request, validates the data, and calls the appropriate service to process the transaction. It could involve communicating with payment providers, updating databases, and sending confirmation messages.&lt;/li&gt;
&lt;li&gt;Manage user accounts: Controllers handle user registration, login, and other account-related actions. They interact with the user model to store and retrieve data, ensuring secure authentication and authorization.&lt;/li&gt;
&lt;li&gt;Orchestrate complex workflows: Payment gateways often involve intricate processes with multiple steps. Controllers act as the glue, coordinating the flow of data between different components and ensuring everything runs smoothly.&lt;/li&gt;
&lt;li&gt;Handle errors gracefully: When something goes wrong, controllers catch the errors, log them appropriately, and provide informative responses to the users or APIs making the request.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here’s an example of how a controller might handle the “collect” request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
export async function collect(data:any, res:any){
    // Validate type and amount from request body
    const { type, amount } = data;
    if (!type || !amount) {
        return res.status(400).json({
        error: "Missing required fields",
        });
    }

    // Process payment based on type
    try {
        if (type === "mobile_money") {
            // Call a controller or service that handles mobile money payments
            // Send confirmation message and status
            res.status(200).json({
                message: "Mobile Money Payment initiated successfully",
                status: "pending",
            });
        } else if (type === "card_payment") {
            // Call a controller or service that handles card payments
            // Send confirmation message and status
            res.status(200).json({
                message: "Card Payment initiated successfully",
                status: "pending",
            });
        } else {
            return res.status(400).json({
                error: "Invalid payment type",
            });
        }
    } catch (error) {
        // Handle and log errors
        console.error(error);
        res.status(500).json({
            error: "Internal server error",
        });
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, the controller takes care of the entire payment flow, from validation to service calls and response generation. When we run our previous collect route we get the response as shown below.&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%2Fka00n5gtdm24eahu8jeh.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%2Fka00n5gtdm24eahu8jeh.png" width="800" height="458"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Response from collect route handled by the collect controller&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Using controllers brings several benefits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Improved code organization: Code is divided into clear, reusable modules, making it easier to understand, maintain, and test.&lt;/li&gt;
&lt;li&gt;Reduced redundancy: Logic is centralized in controllers, preventing duplication across routes and other components.&lt;/li&gt;
&lt;li&gt;Enhanced flexibility: New features and functionalities can be easily implemented by adding new controllers or modifying existing ones.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By leveraging the power of controllers, you can build a robust and scalable payment gateway that can handle complex transactions with ease. Stay tuned for the next part, where we’ll dive deeper into specific controller implementations and explore how they interact with other parts of the system!&lt;/p&gt;

&lt;p&gt;Next we will look at services to further handle our controller functionalities, then we will also look at practices that we can use to make our code better including logging methods, migrations, setup and handling scripts among others. And in case if you want to view the code you can always check it below.&lt;/p&gt;

&lt;p&gt;Until the next blog, happy coding.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Cank256/payie" rel="noopener noreferrer"&gt;GitHub - Cank256/payie: A payment solution project&lt;/a&gt;&lt;/p&gt;




</description>
      <category>payments</category>
      <category>node</category>
      <category>paymentgateway</category>
    </item>
    <item>
      <title>Navigating the Web: The Symphony of a Web Request</title>
      <dc:creator>Caleb Nkunze</dc:creator>
      <pubDate>Mon, 11 Dec 2023 05:24:23 +0000</pubDate>
      <link>https://dev.to/cank256/navigating-the-web-the-symphony-of-a-web-request-3coa</link>
      <guid>https://dev.to/cank256/navigating-the-web-the-symphony-of-a-web-request-3coa</guid>
      <description>&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%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F0%2ADf5ZKNn21VzJl85p" 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%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F0%2ADf5ZKNn21VzJl85p" width="1024" height="683"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Photo by Lars Kienle on Unsplash&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Ever wondered about the intricate dance of technology that unfolds when you type “&lt;a href="https://www.google.com/" rel="noopener noreferrer"&gt;https://www.google.com&lt;/a&gt;" into your browser and press Enter? Join me on a journey through the web’s inner workings as we unravel the orchestration of DNS requests, TCP/IP, firewalls, HTTPS/SSL, load-balancers, web servers, application servers, databases, and the final leg — your client device.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;DNS Request&lt;/strong&gt; : The journey begins with a DNS (Domain Name System) request. Your browser sends a query to translate the human-readable “&lt;a href="http://www.google.com/" rel="noopener noreferrer"&gt;www.google.com&lt;/a&gt;" into an IP address. The DNS server, acting as a digital phone book, responds with the corresponding IP address, allowing your browser to locate Google’s servers on the internet.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TCP/IP:&lt;/strong&gt; With the IP address in hand, your browser initiates a TCP (Transmission Control Protocol) connection with Google’s server. TCP ensures a reliable and ordered exchange of data, breaking it into packets and managing their secure transmission between your device and Google’s servers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Firewall:&lt;/strong&gt; As the request reaches Google’s servers, it encounters a firewall — a digital guardian protecting against unauthorized access. The firewall evaluates the incoming traffic, allowing or denying access based on predefined security rules. This layer of defense ensures the integrity and security of Google’s infrastructure.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;HTTPS/SSL:&lt;/strong&gt; To secure the data exchange between your browser and Google’s servers, the connection transitions to HTTPS (Hypertext Transfer Protocol Secure) using SSL (Secure Sockets Layer) or TLS (Transport Layer Security). This encryption safeguards your information from potential eavesdropping and tampering during transit.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Load-Balancer:&lt;/strong&gt; Google manages a colossal amount of traffic, and a load-balancer steps in to distribute this load efficiently. It directs your request to an optimized server, ensuring even resource utilization, preventing overload, and enhancing the overall reliability and performance of the service.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Web Server:&lt;/strong&gt; Once the load-balancer selects a server, the web server takes center stage. Google employs highly efficient web servers like Google Frontend, responsible for handling static content, processing your request, and returning the initial HTML page of the Google search.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Application Server:&lt;/strong&gt; For dynamic content, your request is handed over to an application server. Google’s sophisticated applications execute server-side code, interact with databases, and generate dynamic content based on your search query. This stage adds the intelligence and personalization that make Google searches so powerful.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Database:&lt;/strong&gt; Behind every search result is a database. Google’s databases store and manage vast amounts of information, delivering relevant search results rapidly. The application server communicates with the database server to retrieve the requested information, completing the intricate dance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Client:&lt;/strong&gt; The journey concludes as the response, now containing search results and dynamic content, travels back to your client device. Your browser renders the HTML page, fetching additional resources like images and scripts. You now interact with the familiar Google search interface, clicking links and exploring the web, all facilitated by the seamless technology symphony.&lt;/li&gt;
&lt;/ol&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%2Ff772ah66tq85ncoc5zrh.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%2Ff772ah66tq85ncoc5zrh.png" width="800" height="262"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Caleb N — Gliffy&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Conclusion: From DNS requests to client rendering, the journey of typing “&lt;a href="https://www.google.com/" rel="noopener noreferrer"&gt;https://www.google.com&lt;/a&gt;" into your browser is a fascinating orchestration of technology. Each component, from firewalls to load-balancers, contributes to the seamless, secure, and lightning-fast experience we’ve come to expect from the world’s most popular search engine. Understanding this intricate process enhances our appreciation for the sophisticated infrastructure that powers our interactions with the digital world.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>NodeJS Gateway — Part 3: Routes and Middleware</title>
      <dc:creator>Caleb Nkunze</dc:creator>
      <pubDate>Sun, 05 Feb 2023 12:52:32 +0000</pubDate>
      <link>https://dev.to/cank256/nodejs-gateway-part-3-routes-and-middleware-2ojd</link>
      <guid>https://dev.to/cank256/nodejs-gateway-part-3-routes-and-middleware-2ojd</guid>
      <description>&lt;h3&gt;
  
  
  NodeJS Gateway — Part 3: Routes and Middleware
&lt;/h3&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%2Fz8m7khe31s48r1sri6p4.jpeg" 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%2Fz8m7khe31s48r1sri6p4.jpeg" alt="Routes" width="800" height="540"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Photo by Bogdan Karlenko on Unsplash&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This is part of the Building a payment gateway using JavaScript series. You can check out the previous parts below;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Intro:&lt;/strong&gt; &lt;a href="https://dev.to/cank256/how-i-built-a-payment-gateway-using-javascript-472-temp-slug-1856034"&gt;How I built a Payment Gateway using JavaScript&lt;/a&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Part 1:&lt;/strong&gt; &lt;a href="https://dev.to/cank256/nodejs-gateway-part-1-initial-setup-525h-temp-slug-1024839"&gt;Initial Setup&lt;/a&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Part 2:&lt;/strong&gt; &lt;a href="https://medium.com/dev-genius/nodejs-gateway-part-2-setting-up-our-database-mongodb-f947e5746a4b" rel="noopener noreferrer"&gt;Setting Up our Database (MongoDB)&lt;/a&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Part 3 (Here):&lt;/strong&gt; Routes and Middleware&lt;/p&gt;
&lt;h3&gt;
  
  
  Routes
&lt;/h3&gt;

&lt;p&gt;With NodeJS, comes the popular Express JS which is an open-source Node.js framework for building web applications. It provides a simple and flexible way to create server-side applications, handling HTTP requests and responses, routing, middleware, and more. Express makes it easy to build fast and scalable APIs, as well as dynamic web pages, and has a large community of developers who contribute to its development and offer support. With Express, developers can build robust and reliable web applications with a minimum of code and effort.&lt;/p&gt;

&lt;p&gt;We can now go ahead and install Express in our application using the command below in our terminal.&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 express --save
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Great now we can create our routes. Since we are creating a payment gateway, lets use 2 endpoints that is &lt;strong&gt;status&lt;/strong&gt; and  &lt;strong&gt;collect&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For the endpoint responses you can have any data that you believe will be helpful to the API consumer, therefore, our responses will have a JSON structure as below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "code": 200,
  "status": "success",
  "data": {}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From the above the code value can be any HTTP status code according to the action carried out and the status value has to correspond with the code.&lt;/p&gt;

&lt;p&gt;You can learn more about the HTTP status codes below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status" rel="noopener noreferrer"&gt;HTTP response status codes - HTTP | MDN&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And from the introduction of these series, we are going to follow RESTFul API practices. To know more about these you can visit the sites below.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://learn.microsoft.com/en-us/azure/architecture/best-practices/api-design" rel="noopener noreferrer"&gt;Web API design best practices - Azure Architecture Center&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://aws.amazon.com/what-is/restful-api/" rel="noopener noreferrer"&gt;What is RESTful API? - RESTful API Beginner's Guide - AWS&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Alright, let’s go ahead and create our 2 endpoints under api routes as below.&lt;/p&gt;

&lt;p&gt;First we have the status endpoint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//This is in the index.ts file under the routes folder
import express from 'express'
const router = express.Router();
const transactions = require('./transactions');

router.use(transactions);

router.get("/status", (req, res) =&amp;gt; {
    console.log('here');
    res.status(200).json({
        code: 200,
        status: "success",
        data: {
            app: "Gateway",
            msg: "You are welcome to my amazing payment gateway"
        }
    })
});

export default router;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From the above you can see that we imported the transaction routes that we used in our last step in to the index file of the routes, this can be helpful in organising our code so that we can just import only the index file in the app.ts file of the gateway.&lt;/p&gt;

&lt;p&gt;When we start the Node server (refer to previous steps), we will get the response for this endpoint similar to the one below.&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%2Fbfnblelqjqzx5slhlr4j.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%2Fbfnblelqjqzx5slhlr4j.png" width="800" height="569"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Response from the status endpoint.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now let’s move to the collect endpoint. This will be the one used to initiate or complete payments. And our endpoint will look as below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import express from 'express'
const router = express.Router();
import { collect } from '../controllers/collect'

router.post("/collect", (req, res) =&amp;gt; {
    //call the collection function from the controller
    collect(req.body, res)

});

export default router;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looking at our code, you can see that we imported the collect function from the collect controller (we will be looking at controllers in our next step) and we called it in the endpoint function. This means that when when we request to collect payment, the endpoint will relay our request and data over to the collect function to be processed as desired. We can also see that our endpoint uses the POST method and not the GET method like for our status.&lt;/p&gt;

&lt;p&gt;A simple way of explaining how to use the 2 methods is, the GET method carries parameters appended in the URL for example an ID for a transaction whose status you can to get while to the POST method the parameters are carried in the body of the request.&lt;/p&gt;

&lt;p&gt;Read more about this here&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.w3schools.com/tags/ref_httpmethods.asp" rel="noopener noreferrer"&gt;HTTP Methods GET vs POST&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and here&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.geeksforgeeks.org/difference-between-http-get-and-post-methods/" rel="noopener noreferrer"&gt;Difference between HTTP GET and POST Methods - GeeksforGeeks&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can now add our collect endpoint to the index route file as below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import express from 'express'
const router = express.Router();
import transactions from './transactions';
import collect from './collect';

router.use(transactions);
router.use(collect);

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

&lt;/div&gt;



&lt;p&gt;We can now go ahead and build then run the server. We will get a response as below for our collect endpoint.&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%2F3usk3sspdk98ck5dfell.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%2F3usk3sspdk98ck5dfell.png" width="800" height="569"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Response for the collect endpoint&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You can see that the response is different, do not worry the response was generated by a function which our route directed the request to.&lt;/p&gt;
&lt;h3&gt;
  
  
  Middleware
&lt;/h3&gt;

&lt;p&gt;This refers to functions that have access to the request and response objects, and can perform actions such as parsing incoming requests, adding headers, or performing authentication and authorization. Middleware functions in web development can be thought of as “glue” that ties together different parts of an application and allows them to work together.&lt;/p&gt;

&lt;p&gt;In frameworks such as Express.js, middleware is an important concept that allows developers to extend the functionality of their application by adding custom logic to the request/response cycle. Middleware functions can be added to an Express application by using the app.use() method, and they are executed in the order they are defined. This makes it easy to add or modify the behavior of an application, and can help to keep code clean and organized. If you have been following, we added our routes via app.use() in the app.ts file. In the Initial Step of these series we also looked at how the body-parser middleware was added using the same method.&lt;/p&gt;

&lt;p&gt;You can also create a customised middleware according to what your desire is. They can be added in the app.ts file to work globally or for a specific function or even route. For example we can to pass a collection type value in the body of our collect request.&lt;/p&gt;

&lt;p&gt;We can create a middleware that returns a error if the type value is not passed in the request body. For this we can use body which is a function provided by a NodeJS package called express-validator, and we are going to use it to check if type is available and not null in the request body of the collect endpoint.&lt;/p&gt;

&lt;p&gt;First we install express-validator&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 express-validator --save
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can now implement it in our collect endpoint to check the body for a value of type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//This is in the collect router file
import express from 'express'
const router = express.Router();
const { body, validationResult } = require('express-validator');
import { collect } from '../controllers/collect'

router.get("/collect", body('type').not().isEmpty(), (req, res) =&amp;gt; {
    //Use Middleware to check if required values are available
    const errors = validationResult(req);
    if (!errors.isEmpty()) {
        return res.status(400).json({ 
            code: 400,
            status: "error",
            data: errors.array() 
        });
    }

    //call the collection function from the controller
    collect(req.body, res)

});

export default router;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above, we are checking if the type value in the body is not Empty, and to pass on the request to the controller if provided or return an error response if null.&lt;/p&gt;

&lt;p&gt;Below is a response we get if we do not provide a value for type.&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%2F54xsexbx0a6n6vl27qxx.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%2F54xsexbx0a6n6vl27qxx.png" width="800" height="569"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Error response from middleware.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Below is the response we get if we provide the type value in the request body.&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%2Flxpr6y5le88umpyo6ui0.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%2Flxpr6y5le88umpyo6ui0.png" width="800" height="569"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Success Response&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The middleware can be customised further to help in securing the API access by checking for Authorisation headers, and sanitising the request for proper processing. There also other important middleware tat you can use in your project for example helmet (configure HTTP headers), cors (for Cross-Origin Resource Sharing configs) etc.&lt;/p&gt;

&lt;p&gt;You can see the final code using the link below, otherwise let’s catchup in the next step talking about controllers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Cank256/payie" rel="noopener noreferrer"&gt;GitHub - Cank256/payie: A payment solution project&lt;/a&gt;&lt;/p&gt;




</description>
      <category>announcement</category>
      <category>devto</category>
      <category>web3</category>
      <category>crypto</category>
    </item>
    <item>
      <title>NodeJS Gateway — Part 2: Setting Up our Database (MongoDB)</title>
      <dc:creator>Caleb Nkunze</dc:creator>
      <pubDate>Tue, 30 Aug 2022 20:51:56 +0000</pubDate>
      <link>https://dev.to/cank256/nodejs-gateway-part-2-setting-up-our-database-mongodb-1d2b</link>
      <guid>https://dev.to/cank256/nodejs-gateway-part-2-setting-up-our-database-mongodb-1d2b</guid>
      <description>&lt;h3&gt;
  
  
  NodeJS Gateway — Part 2: Setting Up our Database (MongoDB)
&lt;/h3&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%2F7p9dg4horxyr51zbgr4e.jpeg" 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%2F7p9dg4horxyr51zbgr4e.jpeg" width="800" height="539"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Photo by Rubaitul Azad on Unsplash&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;NoSQL databases make it easy to start developing your project or application with basic schemas, and since consistency can be jumped over with this type of database, expansion becomes easy as our variables and interactions increase and this is why we are using MongoDB for our gateway. This is also because the API application (refer to the link below about the project we are building) will be the one holding all the final transactional or interaction data (Postgres).&lt;/p&gt;

&lt;p&gt;Just in case you are confused of what we are developing, please visit the link below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/@nkunzecaleb/how-i-build-a-payment-gateway-using-javascript-2e4f3e52b7cd" rel="noopener noreferrer"&gt;How I built a Payment Gateway using Javascript.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the previous post (Part 1), we were able to add the mongodb and mongoose npm modules to our gateway. In this post, we are going to concentrate on creating collections’ schemas, saving, retrieving, updating and deleting data from our database collections.&lt;/p&gt;

&lt;p&gt;If you are wondering what collections are, you can relate them to tables or relations in SQL databases. Since the NoSQL databases are non-tabular databases which consist of JSON-like documents types of databases among other of which MongoDB is part. Therefore, the records (in SQL databases) or entries are documents in NoSQL, and a collection is a group of documents (records). I hope that is not confusing. You check out more broad explanations here &lt;a href="https://www.mongodb.com/nosql-explained" rel="noopener noreferrer"&gt;NoSQL Explained&lt;/a&gt;, &lt;a href="https://www.techtarget.com/searchdatamanagement/definition/NoSQL-Not-Only-SQL" rel="noopener noreferrer"&gt;TechTarget&lt;/a&gt; and &lt;a href="https://www.couchbase.com/resources/why-nosql" rel="noopener noreferrer"&gt;NoSQL Databases&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We are going to look at inserting data for a basic demo internal (app) transfer transaction having transaction_id transaction_type sender_account_id recipient_account_id amount currency transaction_note then date_time .&lt;/p&gt;

&lt;p&gt;First, we will start with creating a schema which in simple terms is the format of the data that is to be saved in the database. Let’s go ahead and create a model file transactionModel.ts for our transaction data and add the following code.&lt;/p&gt;

&lt;a href="https://medium.com/media/af9a5e596d29b884536a4a9890ee1185/href" rel="noopener noreferrer"&gt;https://medium.com/media/af9a5e596d29b884536a4a9890ee1185/href&lt;/a&gt;

&lt;p&gt;From the code, we see that all inputs are required apart from the transaction note which is optional. After defining the schema transactionSchema we create the transactionModel as on line 13 which will be used in searching, saving and retrieving transaction related data. Remember, this is basic and we will add on more values or variables as we go on.&lt;/p&gt;

&lt;p&gt;Let’s go ahead and test our model to see if we can save and retrieve data from the database. And to do this, we are going to create 3 routes for saving and retrieving our transaction data.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;POST /api/transaction Create a transaction&lt;/li&gt;
&lt;li&gt;GET /api/transaction/:id Get transaction data for a single transaction&lt;/li&gt;
&lt;li&gt;GET /api/transactions Get All transactions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This part is more about database so we will not go deeper into routes. For now we can have basic routing to test our schema. For this, we are going to add a body-parser module that will help us make a middleware to convert our requests data to JSON format for storing. Use the command below.&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 body-parser --save
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can add the code below to our app.ts file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const bodyParser = require('body-parser');

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So that we have the app.ts looking like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/media/cf24dbf144c37c944e8402a9ebda76d1/href" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;a href="https://medium.com/media/cf24dbf144c37c944e8402a9ebda76d1/href" rel="noopener noreferrer"&gt;https://medium.com/media/cf24dbf144c37c944e8402a9ebda76d1/href&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We then create a transactions route file transactions.ts in the routes folder. Finally we add the code below to it:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/media/0259d5c56c2d71226309875d23263120/href" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;a href="https://medium.com/media/0259d5c56c2d71226309875d23263120/href" rel="noopener noreferrer"&gt;https://medium.com/media/0259d5c56c2d71226309875d23263120/href&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can run npm run start to build and start our server.&lt;/p&gt;

&lt;p&gt;From the above code save the transaction created by calling the mongoose start() function on the request body data received, and this sends back a response to the client when the saving process is successful or not. See the screenshot below from postman.&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%2Fopkkc2l0yev4o8l98jk6.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%2Fopkkc2l0yev4o8l98jk6.png" width="800" height="484"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;The POST request for saving the transaction details (Successful)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To get one transaction, we pass the id parameter in the route which is used to search for the transaction similar to the transactionId that it was generated during the transaction creation. See the screenshot below from postman.&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%2F3hoj8fz29w2n30a2i0rq.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%2F3hoj8fz29w2n30a2i0rq.png" width="800" height="484"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;The GET request to retrieve a single transaction (Successful)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Then we can also query for all transactions to be returned by passing no argument in the find() function of mongoose. See the screenshot below from postman.&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%2Fj6yudldxjvqvfxpe8e5u.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%2Fj6yudldxjvqvfxpe8e5u.png" width="800" height="484"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;The GET request to retrieve all transactions (Successful)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A failed action will look as below in postman.&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%2Fpobf5gza0cs6ln5mc1f8.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%2Fpobf5gza0cs6ln5mc1f8.png" width="800" height="484"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;A failed GET request for retrieval of a single transaction.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Well done for coming all this way, we have seen how we will be interacting with our database, and in other parts we will be looking at modifications and deleting of our data from the database.&lt;/p&gt;

&lt;p&gt;I would like to thank you again for finishing this post, you can clap or even follow me for more posts like this as I traverse through my journey of creating a payment gateway. Please be free to rectify me on where I went wrong. Learning is the way to Go.&lt;/p&gt;

&lt;p&gt;Next we will be looking at routes, middleware and hopefully controllers. I try to make these as short as possible to avoid having a full text book in one go 🤩.&lt;/p&gt;

&lt;p&gt;In case you want to see the finished code (up-to-this stage), you can get it from the repo using the link below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Cank256/payie" rel="noopener noreferrer"&gt;GitHub - Cank256/payie: A payment solution project&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Till next post 😎.&lt;/p&gt;




</description>
      <category>mongoose</category>
      <category>typescript</category>
      <category>javascript</category>
      <category>node</category>
    </item>
    <item>
      <title>NodeJS Gateway — Part 1: Initial Setup</title>
      <dc:creator>Caleb Nkunze</dc:creator>
      <pubDate>Tue, 23 Aug 2022 17:58:16 +0000</pubDate>
      <link>https://dev.to/cank256/nodejs-gateway-part-1-initial-setup-2m87</link>
      <guid>https://dev.to/cank256/nodejs-gateway-part-1-initial-setup-2m87</guid>
      <description>&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%2F4dlbo8p9w8d460fjxfzc.jpeg" 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%2F4dlbo8p9w8d460fjxfzc.jpeg" width="800" height="485"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Photo by Ferenc Almasi on Unsplash&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It’s been a little over 3 months since my last post about building a payment solution using Javascript.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/@nkunzecaleb/how-i-build-a-payment-gateway-using-javascript-2e4f3e52b7cd" rel="noopener noreferrer"&gt;How I built a Payment Gateway using Javascript.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yes, it can be overwhelming at times with a 9–5, am glad was able to finally do part of the would be series of how to build a payment gateway or solution using Javascript.&lt;/p&gt;

&lt;p&gt;In the last post I talked about why I chose JavaScript which I will not be repeating here, however, I have come to realise that using other frameworks (not for Javascript) or languages can also give you a a pretty good and robust solution as well. Therefore, I will in the future share about using other languages (PHP and Python) and frameworks (Laravel and Django) to come up with similar or even better solutions. It all comes to which one you’re well conversant about.&lt;/p&gt;

&lt;p&gt;Alright enough of that, let’s dive into the Gateway (JavaScript — NodeJS).&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;The Start&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;With this, we will be using TypeScript which I believe is an advantage over using just JavaScript to avoid errors that may have sneaked through to the runtime. You see, basic JavaScript is dynamic and weak-typed which can bring up challenges in managing a growing code base while TypeScript which is a super-set of JavaScript has strong static typing, compilation, and object oriented programming characteristics which come in handy when looking at large code projects or ever growing code bases like a payment gateway (from the previous blog, you will see that we are looking at having Mobile money integrations, VISA and MasterCard, SMS, Email and other billing and security features that tend to keep changing overtime)&lt;/p&gt;

&lt;p&gt;Since we have that out of the way let’s start with setup our gateway with TypeScript, Express and MongoDB.&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 1
&lt;/h4&gt;

&lt;p&gt;We will create our folder and move into it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mkdir gateway
$ cd gateway
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we can go ahead and initialise our npm project:&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
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can use the -y flag to use defaults of npm init by automatically saying yes. However, for me I love to make it personal 😎 so I came up with something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/media/aec0d90a82cc171eb8bd709a864bd13f/href" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;a href="https://medium.com/media/aec0d90a82cc171eb8bd709a864bd13f/href" rel="noopener noreferrer"&gt;https://medium.com/media/aec0d90a82cc171eb8bd709a864bd13f/href&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 2 - Add and Configure TypeScript
&lt;/h4&gt;

&lt;p&gt;After initialising our project, next is adding and configuring TypeScript. Remember that this is done inside our gateway folder.&lt;/p&gt;

&lt;p&gt;First we install TypeSript as below:&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 --save-dev typescript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We then add a tsconfig.json file to the root directory gatewaywhich is used to configure the compilation options of TypeScript.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Then insert the code below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/media/cd67a9205e7ff6e03b178482657424d2/href" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;a href="https://medium.com/media/cd67a9205e7ff6e03b178482657424d2/href" rel="noopener noreferrer"&gt;https://medium.com/media/cd67a9205e7ff6e03b178482657424d2/href&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Looking at the snippet above, here is simple explanation for the variables we have used:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;module: Specifies the module code generation method. Node uses commonjs.&lt;/li&gt;
&lt;li&gt;esModuleInterop :Enables interoperability between CommonJS and ES modules during imports.&lt;/li&gt;
&lt;li&gt;target: Specifies the output language level (we are using ES6).&lt;/li&gt;
&lt;li&gt;moduleResolution: This helps the compiler figure out what an import refers to. The value node mimics the Node module resolution mechanism.&lt;/li&gt;
&lt;li&gt;sourceMap : Creates respective .map file for allowing debuggers and other tools to display the original TypeScript source code when working with the emitted JavaScript files.&lt;/li&gt;
&lt;li&gt;outDir: This is the location to output .js files after compilation. In our project we will use thedistfolder.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Read more about this here &lt;a href="https://www.typescriptlang.org/docs/handbook/compiler-options.html" rel="noopener noreferrer"&gt;TypeScript Compiler options&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 3 - Add and Configure Express server
&lt;/h4&gt;

&lt;p&gt;Let’s start by installing 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 install --save express
$ npm install -save-dev @types/express

//We use the @types/express package for TypeScript to know about the types of Express classes.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we create the src folder in our gateway folder to hold our TypeScript files which have a .ts extension:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mkdir src
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we add a file called app.ts which will act as our main project app which we will later add the respective transpiled app.js file in the package.json to run as the main file instead of 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;$ nano src/app.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the code below to create a minimalistic express server:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/media/993302f8d71d9e291686e1c329801959/href" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;a href="https://medium.com/media/993302f8d71d9e291686e1c329801959/href" rel="noopener noreferrer"&gt;https://medium.com/media/993302f8d71d9e291686e1c329801959/href&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above code creates an express server that runs on port 3000 . Let’s go ahead and compile, then run our server to test if everything works fine. To compile, we run the command below in the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npx tsc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above uses the configuration options in tsconfig.json to generate .js files in the dist folder which we will use in running the app as below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ node dist/app.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For a successful run we will have the output below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Express is listening at [http://localhost:3000](http://localhost:3000)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can open the link in the browser and you should be able to see Hello World! in the browser. Hurayyyy!! You have setup and configure your express server. You can open the dist/app.js and see how it looks like. Below is a snippet.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/media/d0578224bb3e187f6d6f5ef265e25588/href" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;a href="https://medium.com/media/d0578224bb3e187f6d6f5ef265e25588/href" rel="noopener noreferrer"&gt;https://medium.com/media/d0578224bb3e187f6d6f5ef265e25588/href&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, let’s install and configure MongoDB.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 4 - Add and Configure MongoDB
&lt;/h4&gt;

&lt;p&gt;First, you need to make sure that you have MongoDB installed and running on your machine, you can use the links below for instructions to install, run and create a database (for our case it should be gateway)according to the operating system you have.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;On MacOS&lt;/strong&gt;
&lt;a href="https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-os-x/" rel="noopener noreferrer"&gt;https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-os-x/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;On Linux&lt;/strong&gt; &lt;a href="https://www.mongodb.com/docs/manual/administration/install-on-linux/" rel="noopener noreferrer"&gt;https://www.mongodb.com/docs/manual/administration/install-on-linux/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;On Windows&lt;/strong&gt;
&lt;a href="https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-windows/" rel="noopener noreferrer"&gt;https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-windows/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can go ahead and add mongodband mongoose to our project using the command below:&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 mongodb mongoose
$ npm install -save-dev [@types/mongodb](http://twitter.com/types/mongodb) @types/mongoose
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next we are going to connect to our database that we created by updating our app.ts code as below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/media/d2c6d70197c8fab90cbf22b1e11ebda2/href" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;a href="https://medium.com/media/d2c6d70197c8fab90cbf22b1e11ebda2/href" rel="noopener noreferrer"&gt;https://medium.com/media/d2c6d70197c8fab90cbf22b1e11ebda2/href&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have imported the mongoose module and used it to connect to our database which uses the url mongodb://localhost:27017/gateway. On a successful db connection the express server will be started and you will get the output below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Express is listening at [http://localhost:3000](http://localhost:3000)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wow! It has been a long thread but I am thankful that you took time to go through it all. It will be great if you give a clap or even follow me for future posts in this series and other topics. Next we will be looking at database actions.&lt;/p&gt;

&lt;p&gt;In case you want the code used in this post, you can use the link below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Cank256/payie/" rel="noopener noreferrer"&gt;GitHub - Cank256/payie: A payment solution project&lt;/a&gt;&lt;/p&gt;




</description>
      <category>nodejsdevelopment</category>
      <category>paymentgateway</category>
      <category>mongodb</category>
      <category>express</category>
    </item>
    <item>
      <title>How I built a Payment Gateway using Javascript.</title>
      <dc:creator>Caleb Nkunze</dc:creator>
      <pubDate>Tue, 17 May 2022 10:34:00 +0000</pubDate>
      <link>https://dev.to/cank256/how-i-built-a-payment-gateway-using-javascript-78h</link>
      <guid>https://dev.to/cank256/how-i-built-a-payment-gateway-using-javascript-78h</guid>
      <description>&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%2Fbqendy5ubji9hezitknm.jpeg" 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%2Fbqendy5ubji9hezitknm.jpeg" width="800" height="533"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Photo by Pankaj Patel on Unsplash&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;After my University studies (about 5 years back), I had a desire to build a project not only to generate income, but to enable other people and teams generate and manage their income as well.&lt;/p&gt;

&lt;p&gt;Despite my studies Information Technology, I had acquired little knowledge in JAVA and C/C++ languages and could hardly create any application using any of them yet they are amazing development languages. I ventured out in to easy-to-learn languages like Javascript, Python and PHP (Yess… I know what is running through your mind, but PHP seemed way easy for me). I was able to use their respective frameworks in different working environments like NodeJS and VueJS (for Javascript), Django (for Python) and CodeIgniter, Symfony, Laravel (for PHP).&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;The project&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Finally, the time came for me to get back on course of creating my own project. I had thinking sessions and research for problems I could solve. I decided to look first into the challenges faced in generating and managing income in my country and region Uganda (East Africa), thus coming up with an idea of developing a simple yet robust payment platform to serve individuals, companies/organisations and other developers to integrate the available payment methods (Mobile Money and Card payments) in to their day to day transactions activities.&lt;/p&gt;

&lt;p&gt;The platform was to have the Gateway which would communicate directly with the Third-Party service providers like mobile money networks, the api (backend) which will serve the frontend and also help developers integrate the platform’s functionalities into their own apps and a user interface for users to manage their transactions (Wallet) and carry out other payments like top up airtime, data bundles and so on. And later a mobile app to complement the web app.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;The structure&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;When it came to choosing the language and/or framework to use, I decided to go for Javascript. This is because out of all the languages, I wanted to use one that I have better experience with and can provide me with capabilities to create the front and backend with one language since it was a one-man team for the start.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Gateway&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The gateway uses NodeJS, and with it’s single-thread model and good performance, I believe that this will provide a good start off as monitoring is being done to see if we need changes as users and request increase. The database of choice is MongoDB which provides fast read and write capabilities to log transaction statuses which will be used to update the the api part of the project. This will store the data for a short period of time using the &lt;a href="https://www.mongodb.com/docs/manual/reference/glossary/#std-term-TTL" rel="noopener noreferrer"&gt;TTL&lt;/a&gt; collection feature of MongoDB, and most or all the data will be stored by the API.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The API&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The API also uses NodeJS as well and the database of choice was Postgres over MySQL because of it’s provision of a variety of datatypes as I will be using unique datatypes from the basic character and numeric datatypes, and it’s effective ability to easily expand into enterprise level with complex queries and frequent write operations. The API will be able to serve the Dashboard (WebApp/frontend), the developer API and the Mobile App.&lt;/p&gt;

&lt;p&gt;There are a number of NodeJS api boilerplate projects that you can take advantage of to quick start your development, below are some of the ones I took inspiration from:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/hagopj13/node-express-boilerplate" rel="noopener noreferrer"&gt;GitHub - hagopj13/node-express-boilerplate: A boilerplate for building production-ready RESTful APIs using Node.js, Express, and Mongoose&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/danielfsousa/express-rest-boilerplate" rel="noopener noreferrer"&gt;GitHub - danielfsousa/express-rest-boilerplate: ⌛️ Express starter for building RESTful APIs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/madhums/node-express-mongoose" rel="noopener noreferrer"&gt;GitHub - madhums/node-express-mongoose: A boilerplate application for building web apps using node and mongodb&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The Frontend&lt;/strong&gt; (Dashboard)&lt;/p&gt;

&lt;p&gt;The dashboard will enable the users to collect, self-deposit and withdraw money, check their balances, and carry out other transactions like top up data bundles. This will use VueJS framework and NuxtJS for the User Interfaces and handling notifications and alerts for the different activities done by the user.&lt;/p&gt;

&lt;p&gt;I will be sharing more in the next post the breakdown of the above 3 components of this projects for example the authentication, authorisation, request, response and error handling among others.&lt;/p&gt;

&lt;p&gt;Thanks for the read.&lt;/p&gt;

&lt;p&gt;More NodeJS api boiler plate projects:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/kunalkapadia/express-mongoose-es6-rest-api" rel="noopener noreferrer"&gt;GitHub - kunalkapadia/express-mongoose-es6-rest-api: A boilerplate application for building RESTful APIs Microservice in Node.js using express and mongoose in ES6 with code coverage and JsonWebToken Authentication&lt;/a&gt;&lt;/p&gt;




</description>
      <category>softwaredevelopment</category>
      <category>apigateway</category>
      <category>vue</category>
      <category>paymentgateway</category>
    </item>
  </channel>
</rss>
