<?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: Renato</title>
    <description>The latest articles on DEV Community by Renato (@renacargnelutti).</description>
    <link>https://dev.to/renacargnelutti</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%2F351436%2F3953905b-d32e-4d04-b8e7-46ed5120bef5.jpg</url>
      <title>DEV Community: Renato</title>
      <link>https://dev.to/renacargnelutti</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/renacargnelutti"/>
    <language>en</language>
    <item>
      <title>Will Bun.js replace Node.js?</title>
      <dc:creator>Renato</dc:creator>
      <pubDate>Wed, 28 Feb 2024 23:01:41 +0000</pubDate>
      <link>https://dev.to/renacargnelutti/will-bunjs-replace-nodejs-npn</link>
      <guid>https://dev.to/renacargnelutti/will-bunjs-replace-nodejs-npn</guid>
      <description>&lt;p&gt;This is a question that often surfaces whenever a new technology emerges. Recently, this buzz has been around &lt;a href="https://bun.sh/blog/bun-v1.0"&gt;Bun.js v1&lt;/a&gt;, reminiscent of the curiosity and debate when Deno.js was introduced. Understanding the nuances of such technological shifts is crucial, and here's my perspective on it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Introducing Bun.js
&lt;/h3&gt;

&lt;p&gt;Let's delve into what Bun.js is and the reasons behind its growing popularity:&lt;/p&gt;

&lt;p&gt;According to the &lt;a href="https://bun.sh/"&gt;official documentation&lt;/a&gt;, Bun.js is &lt;em&gt;"an all-in-one JavaScript runtime &amp;amp; toolkit designed for speed, which includes a bundler, test runner, and a Node.js-compatible package manager."&lt;/em&gt; What sets it apart from Node.js is its foundation in Zig and utilization of JavaScriptCore, offering significant improvements in startup times and memory efficiency.&lt;/p&gt;

&lt;p&gt;Here are some key advantages of Bun.js:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Speed&lt;/strong&gt;: Bun.js boasts a startup time that is four times faster than that of Node.js.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TypeScript &amp;amp; JSX Support&lt;/strong&gt;: Directly execute &lt;code&gt;.jsx&lt;/code&gt;, &lt;code&gt;.ts&lt;/code&gt;, and &lt;code&gt;.tsx&lt;/code&gt; files. Bun.js transpiles these into vanilla JavaScript, streamlining the development process.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ESM &amp;amp; CommonJS Compatibility&lt;/strong&gt;: As the industry gravitates towards ES modules, Bun.js embraces this transition while maintaining support for the vast number of CommonJS packages.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Web-standard APIs&lt;/strong&gt;: Implementing familiar Web APIs (fetch, WebSocket, ReadableStream) and leveraging JavaScriptCore, Bun.js offers a robust and standard-compliant environment, even utilizing Safari's implementations for certain APIs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Node.js Compatibility&lt;/strong&gt;: Bun.js is not just forward-thinking but also respects the vast ecosystem of Node.js, aiming for comprehensive compatibility with its modules and globals. Although this compatibility journey is ongoing, Bun.js continuously integrates more Node.js APIs, ensuring a smoother transition for developers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The commitment to compatibility alongside innovation is what makes Bun.js a compelling choice for both new and existing Node.js projects.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why the Hype Around Bun.js?
&lt;/h3&gt;

&lt;p&gt;The excitement surrounding Bun.js is not just about its technical prowess. It represents a broader trend toward more integrated, efficient, and web-standard-compliant tooling in JavaScript development. By offering a single solution that encompasses a runtime environment, package manager, and test runner, Bun.js simplifies the developer's toolkit, potentially reducing the cognitive load and streamlining the development process.&lt;/p&gt;

&lt;h3&gt;
  
  
  Performance benchmarks
&lt;/h3&gt;

&lt;p&gt;Bun.js has demonstrated impressive performance metrics when compared to established JavaScript runtimes like Node.js and Deno.js, especially in server-side rendering tasks for React applications. According to benchmark results shared in the documentation, Bun.js achieves almost 5x the speed of Node.js and nearly 2x that of Deno.js in similar conditions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F85fhg3yuwp20ivuqztbv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F85fhg3yuwp20ivuqztbv.png" alt="Chart comparing Bun.js, Node.js, and Deno.js performance" width="800" height="840"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These benchmarks, performed under specific test conditions, highlight Bun.js's efficient handling of server-side rendering requests. While such performance gains are noteworthy, they can vary based on numerous factors, including workload characteristics and deployment environments. Readers interested in a deeper dive into these benchmarks are encouraged to review the detailed results and methodologies provided in the Bun.js documentation, ensuring a comprehensive understanding of its performance capabilities.&lt;/p&gt;

&lt;h3&gt;
  
  
  Production Readiness and Future Potential
&lt;/h3&gt;

&lt;p&gt;While Bun.js showcases impressive performance and a promising set of features, it's crucial to recognize its status as an early-stage project. As with any new technology, adopting Bun.js in a production environment should be approached with careful consideration of its maturity and the specific needs of your application.&lt;/p&gt;

&lt;h4&gt;
  
  
  Current Limitations
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Stability&lt;/strong&gt;: As an evolving project, Bun.js may still be ironing out bugs and stability issues. Frequent updates and changes are expected as it matures.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ecosystem Compatibility&lt;/strong&gt;: While Bun.js aims for broad compatibility with the npm ecosystem and Node.js modules, there may still be gaps or edge cases that could affect complex deployments.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Community Support&lt;/strong&gt;: The user and support community around Bun.js is growing but may not yet offer the depth of resources available for more established technologies.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;In summary, while Bun.js may not be the go-to solution for every production scenario at this stage, its rapid development and the enthusiasm surrounding it suggest a bright future. Developers should consider experimenting with Bun.js in non-critical projects or development environments to gauge its benefits and watch its evolution with interest for potential future adoption.&lt;/p&gt;

&lt;h3&gt;
  
  
  Practical Example with Bun.js and Elysia
&lt;/h3&gt;

&lt;p&gt;To demonstrate Bun.js's capabilities in a real-world scenario, I've developed a simple API using the Elysia framework, an elegant solution optimized for Bun.js. This project serves not only as a proof of concept but also as a sandbox where I've experimented with various features and integrations.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Features of the API:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Framework&lt;/strong&gt;: Utilizes &lt;a href="https://elysiajs.com/"&gt;Elysia&lt;/a&gt;, a framework designed for efficiency and simplicity in Bun.js environments.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Logging&lt;/strong&gt;: Implements advanced logging mechanisms to monitor and debug the API's behavior effectively.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security&lt;/strong&gt;: Integrates the helmet package to enhance the API's security posture against common web vulnerabilities.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Documentation&lt;/strong&gt;: Includes Swagger integration for comprehensive and interactive API documentation, facilitating easier testing and integration for developers.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Explore and Contribute:
&lt;/h3&gt;

&lt;p&gt;I encourage you to explore the API and delve into its codebase to see Bun.js and Elysia in action:&lt;/p&gt;

&lt;p&gt;🔗 &lt;a href="https://github.com/renacargnelutti/elysia-api"&gt;Check out the API on GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feedback, questions, or suggestions? I'm keen to engage with the community and discuss any thoughts you might have about this project or Bun.js in general. Your insights could provide valuable perspectives and contribute to further improvements.&lt;/p&gt;

&lt;p&gt;Feel free to leave a comment or reach out directly. Let's explore the potential of Bun.js together! 😄&lt;/p&gt;

</description>
      <category>node</category>
      <category>bunjs</category>
      <category>programming</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Getting started with Node.js API</title>
      <dc:creator>Renato</dc:creator>
      <pubDate>Thu, 02 Sep 2021 20:46:25 +0000</pubDate>
      <link>https://dev.to/renacargnelutti/getting-started-with-node-js-api-3n99</link>
      <guid>https://dev.to/renacargnelutti/getting-started-with-node-js-api-3n99</guid>
      <description>&lt;h2&gt;
&lt;a id="Nodejs_API_development_powered_by_Express_0"&gt;&lt;/a&gt;Node.js API development powered by Express&lt;/h2&gt;

&lt;h5&gt;
&lt;a id="Note_this_post_is_not_recomended_for_SSR_or_SR_developers_due_to_its_simplicity_2"&gt;&lt;/a&gt;Note: this post is not recomended for SSR or SR developers due to its simplicity.&lt;/h5&gt;

&lt;h2&gt;
&lt;a id="Lets_start_with_a_brief_conceptual_review__4"&gt;&lt;/a&gt;Let’s start with a brief conceptual review 💪&lt;/h2&gt;

&lt;p&gt;First of all let’s talk a little bit about &lt;a href="https://en.wikipedia.org/wiki/Client%E2%80%93server_model"&gt;client-server architecture&lt;/a&gt;. This is a strongly used model to define a way to communicate one or more parts that request some services (clients) and one or more service providers (servers). First of them could be a website or in fact a mobile application, second of them could be a SOAP webservice, Rest API, among others.&lt;br&gt;
We are going to explain one specifical server service called &lt;a href="(https://en.wikipedia.org/wiki/Representational_state_transfer)"&gt;Rest API&lt;/a&gt;, in this opportunity applied with &lt;a href="https://nodejs.org/en/about/"&gt;Node.js&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
&lt;a id="Express_at_a_glance__9"&gt;&lt;/a&gt;Express at a glance 👀&lt;/h2&gt;

&lt;p&gt;This amazing framework will help you build a robust Node.js Rest API. It’s important to know that there are other options to take into account like &lt;a href="https://sailsjs.com/"&gt;Sails&lt;/a&gt;, &lt;a href="https://www.meteor.com/"&gt;Meteor&lt;/a&gt;, &lt;a href="https://hapi.dev/"&gt;Happi&lt;/a&gt;, among others. In this case we will use Express which is the most used one but it doesn’t limit you to use other one. You can read the whole Express documentation &lt;a href="http://expressjs.com/"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
&lt;a id="Requirements__12"&gt;&lt;/a&gt;Requirements 🛠&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://nodejs.org/en/download/"&gt;Node.js&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/nodemon"&gt;Nodemon&lt;/a&gt; (Optional), used to reload the Rest API when a change is introduced on your code. You can install it with npm globally: &lt;code&gt;npm install -g nodemon&lt;/code&gt;, also you can use it with &lt;a href="https://docs.npmjs.com/cli/v7/commands/npx"&gt;npx&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
&lt;a id="Installation__17"&gt;&lt;/a&gt;Installation ⚙️&lt;/h3&gt;

&lt;p&gt;Once the repository is cloned you should install npm packages to be able to run it. To achieve this, just open a terminal on root directory and run the following command:&lt;/p&gt;

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

&lt;h2&gt;
&lt;a id="Lets_start_with_some_code__23"&gt;&lt;/a&gt;Let’s start with some code 💻&lt;/h2&gt;

&lt;p&gt;First of all, I will present the folder structure I chose. That’s so simply and I didn’t include some concepts like services or database acceses.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;.
├── .env
├── .eslintrc.json
├── .gitignore
├── README.md
├── package-lock.json
├── package.json
└── src
    ├── common
    │   └── error.js
    ├── index.js
    ├── middlewares
    │   └── errors.js
    └── routes
        ├── index.js
        └── public.js
&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;.env&lt;/code&gt; file contains environment variables and you must add this file because it won’t be pushed due to &lt;code&gt;.gitigonore&lt;/code&gt; file. We will use &lt;code&gt;API_PORT&lt;/code&gt; variable, then you need to add it just like &lt;code&gt;API_PORT=20000&lt;/code&gt; where &lt;code&gt;20000&lt;/code&gt; is your desired port.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.eslintrc.json&lt;/code&gt; is used to follow some basic coding rules. You can use it or just ignore it.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.gitignore&lt;/code&gt; to defined everything you don’t want to push to git repository. Here is so import to add node_modules.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;README.md&lt;/code&gt; just to show some information about the project.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;package-lock.json&lt;/code&gt; keeps the packages dependencies tree tracked.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;package.json&lt;/code&gt; has every needed dependency for this project.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;src&lt;/code&gt; folder where will leave our core code.
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;common&lt;/code&gt; folder to define common functions used along whole project.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;index.js&lt;/code&gt; that contains main API configuration.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;middlewares&lt;/code&gt; as the name says, contains every API middleware. In this case we only will use just one for error handling.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;routes&lt;/code&gt; folder where the API routing is defined. Here you can find every endpoint of the API.
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;index.js&lt;/code&gt; works like a routes mixer, just that.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;public.js&lt;/code&gt; contains the unique endpoint we have.&lt;/li&gt;
&lt;/ul&gt;




&lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
&lt;a id="Running__58"&gt;&lt;/a&gt;Running ▶️&lt;/h3&gt;

&lt;p&gt;Once npm packages are installed you will be able to run the API. If you have installed &lt;code&gt;nodemon&lt;/code&gt; you can run it with:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    nodemon ./src/index.js
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Otherwise:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    node ./src/index.js
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;After this you should show a message like this on your terminal:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Node.js API listening on port: {Your port defined on .env}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;At this point, you can go to your favourite browser, put &lt;a href="http://localhost"&gt;http://localhost&lt;/a&gt;:{yourDesiderPort}/api/v1/en and check that the response will be:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;{
    "success": true,
    "message": "Node.js API - Hello world"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;
&lt;a id="Available_endpoints__80"&gt;&lt;/a&gt;Available endpoints ✔️&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;GET /api/v1/:lang&lt;/code&gt; where lang is related to a language code. The possible values are &lt;code&gt;['en','es', 'it', 'fr']&lt;/code&gt;. This endpoint will return a specific message depending on the language code sent.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
&lt;a id="Github_repository_link_84"&gt;&lt;/a&gt;Github repository link&lt;/h3&gt;

&lt;p&gt;You can access to the full code in this &lt;a href="https://github.com/renacargnelutti/conceptual-nodejs-express-api"&gt;Github link&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
&lt;a id="Thanks_for_reading__87"&gt;&lt;/a&gt;Thanks for reading! 🙌&lt;/h1&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Do we learn from mistakes/bugs? 💻</title>
      <dc:creator>Renato</dc:creator>
      <pubDate>Sun, 18 Jul 2021 14:58:17 +0000</pubDate>
      <link>https://dev.to/renacargnelutti/do-we-learn-from-mistakes-bugs-20d</link>
      <guid>https://dev.to/renacargnelutti/do-we-learn-from-mistakes-bugs-20d</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;Hi guys, how are you doing? &lt;br&gt;
The main idea of this post is to talk a little bit about our experiences fighting with some bugs or mistakes we know and need to fix but at the end of the problem we learn something. Some of them are invalidating and we can't continue developing and others are just warnings but sometimes we really need them fixed.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I don't wanna motivate you to "learn from bugs/mistakes" because I think the best way to do it is from documentation, but due to my experience I guess we can learn from them.&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  To the point...
&lt;/h1&gt;

&lt;p&gt;I have learnt a lot from some struggling situations, from coding to setting up an environment. I will give a simple example that could help you to understand what I mean.&lt;/p&gt;

&lt;p&gt;I remember facing with Apache Cordova setting up issues a few years ago and with React Native some time after that. In both cases I had to read, to study and to find out a lot of info about that, not just a light search. That time I was using Ubuntu and it was too interesting for me find out how &lt;code&gt;~/.bashrc&lt;/code&gt; or &lt;code&gt;~/.bash_profile&lt;/code&gt; works, and &lt;code&gt;$PATH&lt;/code&gt; as well. &lt;/p&gt;

&lt;p&gt;Simple things maybe for someone with some years of developing experience, but I found it so awesome to learn from that situation.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;This is just a simple sample, but &lt;strong&gt;do you think the same? do you learn from bugs/mistakes?&lt;/strong&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Thanks for reading 🙌 👋
&lt;/h3&gt;

</description>
      <category>discuss</category>
      <category>programming</category>
      <category>productivity</category>
      <category>career</category>
    </item>
    <item>
      <title>Node.js - Getting started with Typescript</title>
      <dc:creator>Renato</dc:creator>
      <pubDate>Sat, 24 Apr 2021 01:53:42 +0000</pubDate>
      <link>https://dev.to/renacargnelutti/node-js-getting-started-with-typescript-j9d</link>
      <guid>https://dev.to/renacargnelutti/node-js-getting-started-with-typescript-j9d</guid>
      <description>&lt;p&gt;Hi folks! How are you?&lt;/p&gt;

&lt;p&gt;This project is just a simple and conceptual REST API trying to get the best of Typescript on Node.js using MongoDB. In this case I've created just a proof of concept. In order to run the project, please go to the end of this post, where you can find out the GitHub repository link.&lt;/p&gt;

&lt;p&gt;I will explain the main parts of the project and you can reply this post with any question you have.&lt;/p&gt;

&lt;p&gt;Let's start with the project structure&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.
├── README.md
├── docs
│   └── OBJECTS\ API.postman_collection.json
├── docker
│   └── docker-compose-dev.yml
├── nodemon.json
├── package-lock.json
├── package.json
├── src
│   ├── constants
│   │   └── index.ts
│   ├── controllers
│   │   ├── object.ts
│   │   └── public.ts
│   ├── index.ts
│   ├── interfaces
│   │   └── object.ts
│   ├── models
│   │   └── object.ts
│   ├── router.ts
│   └── services
│       ├── object.ts
│       └── public.ts
└── tsconfig.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The root level files:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;tsconfig.json&lt;/code&gt;: Typescript configurations (Visit &lt;a href="https://aka.ms/tsconfig.json"&gt;https://aka.ms/tsconfig.json&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;nodemon.json&lt;/code&gt;: nodemon configuration file.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;package.json&lt;/code&gt;: project's dependencies.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;package-lock.json&lt;/code&gt;: automatically generated that contains the dependencies' tree.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Folders:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;/docker&lt;/code&gt;: used only if you don't have a MongoDB server and you wanna run it with docker. To achieve that you have to have Docker and Docker Compose installed and run &lt;code&gt;docker-compose -f docker/docker-compose-dev.yml&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/docs&lt;/code&gt;: there is a Postman json file that you can import to test the API.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/src&lt;/code&gt;: contains the core of the project.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then inside of /src:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;index.ts&lt;/code&gt;: define the API structure and routing and also set MongoDB connection.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/constants&lt;/code&gt;: constants that we need.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/controllers&lt;/code&gt;: manage and define the different routes, but they don't process any thing.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/interfaces&lt;/code&gt;: define the interfaces with data types.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/models&lt;/code&gt;: define the model we need to map to MongoDB.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/services&lt;/code&gt;: process information and connect to the db.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Notice that I'm starting using Typescript and I've just read a few pages about documentation and best practices. My main idea is to improve this code during the next weeks and also to start a kind of discussion with suggestions and comments.&lt;/p&gt;

&lt;p&gt;Thanks for reading and have fun!&lt;br&gt;
👩‍💻🧑‍💻&lt;/p&gt;




&lt;p&gt;IMPORTANT: I was working based on this &lt;a href="https://betterprogramming.pub/pokeapi-rest-in-nodejs-with-express-typescript-mongodb-and-docker-part-1-8428b0cd05d"&gt;post&lt;/a&gt; mainly. Changes were inserted to improve some patterns according to my knowledge.&lt;/p&gt;




&lt;p&gt;Get the full code on &lt;a href="https://github.com/renacargnelutti/nodejs-ts-docker-mongodb"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>typescript</category>
      <category>mongodb</category>
    </item>
    <item>
      <title>Deno REST API / MongoDB or PostgreSQL</title>
      <dc:creator>Renato</dc:creator>
      <pubDate>Mon, 15 Jun 2020 22:12:27 +0000</pubDate>
      <link>https://dev.to/renacargnelutti/deno-rest-api-mongodb-or-postgresql-5g3i</link>
      <guid>https://dev.to/renacargnelutti/deno-rest-api-mongodb-or-postgresql-5g3i</guid>
      <description>&lt;p&gt;Hi folks! This is my first project working with Deno. It's only a 'getting started' kind of project with a simple Rest API and MongoDB/PostgreSQL connection.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;First we need to instal Deno following this &lt;a href="https://deno.land/manual/getting_started/installation"&gt;link&lt;/a&gt;. &lt;br&gt;
In order to use MongoDB or PostreSQL we include them with Docker implementation (Install &lt;a href="https://docs.docker.com/get-docker/"&gt;Docker&lt;/a&gt; and &lt;a href="https://docs.docker.com/compose/install/"&gt;Docker compose&lt;/a&gt;). Otherwise you can use your own database engine, and obviously you have to change your connection string.&lt;/p&gt;
&lt;h2&gt;
  
  
  Features
&lt;/h2&gt;

&lt;p&gt;With this simple project you will be able to test /users endpoints (GET, POST, PUT and DELETE). And you can decide which db use only adding the query string db=mongo or db=postgres.&lt;/p&gt;
&lt;h2&gt;
  
  
  Running the project
&lt;/h2&gt;

&lt;p&gt;If you will use docker-compose you have to run on the root of the project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;docker&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;compose&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;f&lt;/span&gt; &lt;span class="nx"&gt;docker&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;docker&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;compose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;yaml&lt;/span&gt; &lt;span class="nx"&gt;up&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Await a few seconds until databases are ready and then run in another terminal window:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;deno&lt;/span&gt; &lt;span class="nx"&gt;run&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;A&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;allow&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;net&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;allow&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;write&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;allow&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;read&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;allow&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;plugin&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;unstable&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ts&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After this the server has to start and you will be able to make requests.&lt;/p&gt;

&lt;h2&gt;
  
  
  Repository
&lt;/h2&gt;

&lt;p&gt;You can find the repository code &lt;a href="https://github.com/renacargnelutti/deno-rest-api"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Note: I'm working on this project and I will be adding more details and explanations. Let me know if you have a doubt.
&lt;/h3&gt;

</description>
      <category>deno</category>
      <category>mongodb</category>
      <category>node</category>
      <category>postgres</category>
    </item>
    <item>
      <title>Node.js REST API with Docker, Redis and MongoDB</title>
      <dc:creator>Renato</dc:creator>
      <pubDate>Sun, 26 Apr 2020 14:51:50 +0000</pubDate>
      <link>https://dev.to/renacargnelutti/node-js-rest-api-with-docker-redis-and-mongodb-3p7c</link>
      <guid>https://dev.to/renacargnelutti/node-js-rest-api-with-docker-redis-and-mongodb-3p7c</guid>
      <description>&lt;p&gt;Hi guys, this is my first post and I want to share a simple Node.js REST API (Express) that includes Docker, Redis and MongoDB.&lt;/p&gt;

&lt;p&gt;You can run this project with docker-compose, we won't explain anything about it but you refer these links &lt;a href="https://docs.docker.com/install/"&gt;Docker&lt;/a&gt; and &lt;a href="https://docs.docker.com/compose/install/"&gt;Docker Compose&lt;/a&gt;. Check the repo link at the end to be able to run the GitHub project.&lt;/p&gt;

&lt;p&gt;In the file api.js, we use mongoose to connect to MongoDB server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;mongoose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`mongodb://&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;MONGO_INITDB_ROOT_USERNAME&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;:&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;MONGO_INITDB_ROOT_PASSWORD&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;@&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;MONGO_CONTAINER_NAME&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;MONGO_INITDB_DATABASE&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;?authMechanism=SCRAM-SHA-1&amp;amp;authSource=admin`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;useNewUrlParser&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;useCreateIndex&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;useFindAndModify&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;useUnifiedTopology&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;could&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s1"&gt;t connect to Mongo DB &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside libs/redis-client.js you can see the Redis connection:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;redis&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;redis&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;promisify&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;util&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;REDIS_URL&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;error&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Error to connect Redis: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then let's use it:&lt;br&gt;
mongoose -&amp;gt; api/routes/users.js. (Check User schema inside models/user)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// retrieve users&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;({}).&lt;/span&gt;&lt;span class="nf"&gt;lean&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;exec&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;redis -&amp;gt; api/routes/users.js.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// retrieve user&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;rawData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;redisClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// save user&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;redisClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The repo is available at: &lt;a href="https://github.com/renacargnelutti/express-mongo-redis"&gt;https://github.com/renacargnelutti/express-mongo-redis&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope you enjoy the post!&lt;br&gt;
Let me know any question.&lt;/p&gt;

</description>
      <category>node</category>
      <category>mongodb</category>
      <category>redis</category>
      <category>docker</category>
    </item>
  </channel>
</rss>
