<?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: Daniel Boll</title>
    <description>The latest articles on DEV Community by Daniel Boll (@danielboll).</description>
    <link>https://dev.to/danielboll</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%2F479184%2Ff2f5d66e-a265-48b9-99f4-68b9e6c58003.jpeg</url>
      <title>DEV Community: Daniel Boll</title>
      <link>https://dev.to/danielboll</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/danielboll"/>
    <language>en</language>
    <item>
      <title>Unlocking the Power of Native Modules in JavaScript: An Introductory Guide</title>
      <dc:creator>Daniel Boll</dc:creator>
      <pubDate>Fri, 29 Sep 2023 02:29:35 +0000</pubDate>
      <link>https://dev.to/danielboll/unlocking-the-power-of-native-modules-in-javascript-an-introductory-guide-4jh1</link>
      <guid>https://dev.to/danielboll/unlocking-the-power-of-native-modules-in-javascript-an-introductory-guide-4jh1</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0o5uhg17t4tv0g0zu3wg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0o5uhg17t4tv0g0zu3wg.png" alt="Pipeline"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You may also read this blog post in my &lt;a href="https://daniel-boll.me/posts/going-native-on-javascript-1" rel="noopener noreferrer"&gt;blog&lt;/a&gt; for a better experience&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Disclaimer ⚠️&lt;br&gt;
The topic of creating native Node.js modules and working with C++ bindings is intricate,&lt;br&gt;
and while great care has been taken to ensure the accuracy of this blog post, there might be some&lt;br&gt;
inadvertent errors or oversights. The world of native modules is complex, and the documentation can sometimes be heavy to digest.&lt;br&gt;
If you notice any inaccuracies or have suggestions for improvement, please feel free to reach out to me directly or address it&lt;br&gt;
in the comments section below. Your input is highly valuable, not just for me but for everyone else looking to expand their knowledge in this area.&lt;br&gt;
🙇‍♂&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Introduction 🚀
&lt;/h2&gt;

&lt;p&gt;Welcome to the first installment of our series, &lt;code&gt;"Going Native on JavaScript!"&lt;/code&gt; Whether you're a seasoned developer or&lt;br&gt;
just getting started with &lt;b&gt;JavaScript&lt;/b&gt;, you've likely encountered modules — reusable pieces of code that can be imported into your projects.&lt;br&gt;
But have you ever heard of &lt;b&gt;native modules&lt;/b&gt;?&lt;/p&gt;

&lt;p&gt;Native modules are special types of modules that allow you to execute code written in languages like &lt;b&gt;C++&lt;/b&gt; directly within your Node.js application.&lt;br&gt;
These modules can offer significant performance benefits and access to lower-level APIs that are not readily available in JavaScript.&lt;br&gt;
So why aren't native modules as commonly discussed as their pure JavaScript counterparts?&lt;/p&gt;

&lt;p&gt;In this post, we'll delve deep into the world of native modules. We'll explore what they are, why they're critical for certain applications,&lt;br&gt;
and how you can get started with writing your own. Whether you're looking to optimize performance or access unique system-level functionalities,&lt;br&gt;
native modules have a lot to offer.&lt;/p&gt;
&lt;h2&gt;
  
  
  What are Native Modules? 🤔
&lt;/h2&gt;

&lt;p&gt;You may be wondering, &lt;code&gt;"What exactly are native modules, and how do they differ from the JavaScript modules I'm familiar with?"&lt;/code&gt;&lt;br&gt;
Great questions! Native modules are essentially extensions for Node.js that enable execution of lower-level code, typically written in languages&lt;br&gt;
like &lt;b&gt;C++&lt;/b&gt; or &lt;b&gt;Rust&lt;/b&gt;, directly in your Node.js environment.&lt;/p&gt;
&lt;h3&gt;
  
  
  Definition and Key Characteristics 🔍
&lt;/h3&gt;

&lt;p&gt;A native module is a compiled piece of code that acts as a bridge between Node.js and functionalities written in other programming languages.&lt;br&gt;
These modules are generally written in &lt;b&gt;C++&lt;/b&gt; and are loaded dynamically at runtime, allowing them to be used just like any regular &lt;b&gt;JavaScript&lt;/b&gt; module.&lt;/p&gt;
&lt;h3&gt;
  
  
  How Do They Differ From &lt;b&gt;JavaScript&lt;/b&gt; Modules? 🔄
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Performance&lt;/strong&gt;: Native modules often offer performance benefits, especially when it comes to CPU-intensive tasks,&lt;br&gt;
as they run closer to the metal, so to speak.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Capabilities&lt;/strong&gt;: While JavaScript is a powerful language, there are operations it simply cannot perform or can perform only inefficiently.&lt;br&gt;
Native modules fill these gaps by offering functionalities that are not natively available in JavaScript.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Language Interoperability&lt;/strong&gt;: Native modules can be written in multiple languages, giving you the flexibility to integrate codebases in&lt;br&gt;
languages like &lt;b&gt;C++&lt;/b&gt; and &lt;b&gt;Rust&lt;/b&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  In a Nutshell 🥜
&lt;/h3&gt;

&lt;p&gt;&lt;br&gt;
  Native modules serve as a gateway, opening up new possibilities beyond what is achievable using only JavaScript.&lt;br&gt;
  They act as a bridge between the high-level, dynamically-typed world of JavaScript and the lower-level, statically-typed realm of&lt;br&gt;
  languages like C++ or Rust.&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  🎯 Why Use Native Modules?
&lt;/h2&gt;

&lt;p&gt;Native modules are a powerful feature that can dramatically affect how you design and implement Node.js applications.&lt;br&gt;
While they add complexity, the trade-offs can often be worth it, especially in performance-critical applications or&lt;br&gt;
those that require low-level system access. In this section, we dive deeper into why you might consider using native modules in your next project.&lt;/p&gt;

&lt;h3&gt;
  
  
  🚀 Performance Benefits
&lt;/h3&gt;

&lt;p&gt;One of the most compelling reasons to use native modules is the significant performance boost they offer for CPU-bound tasks.&lt;br&gt;
Let's look at some key technical aspects:&lt;/p&gt;

&lt;h4&gt;
  
  
  Compiled Languages
&lt;/h4&gt;

&lt;p&gt;Native modules often utilize compiled languages like &lt;b&gt;C++&lt;/b&gt; or &lt;b&gt;Rust&lt;/b&gt;. Compiled languages generally outperform interpreted languages like&lt;br&gt;
&lt;b&gt;JavaScript&lt;/b&gt; because the code is transformed into machine code, which is directly executable by the computer's CPU.&lt;/p&gt;

&lt;h4&gt;
  
  
  Direct Memory Access
&lt;/h4&gt;

&lt;p&gt;Unlike &lt;b&gt;JavaScript&lt;/b&gt;, which relies on garbage collection and automatic memory management, languages like &lt;b&gt;C++&lt;/b&gt; and &lt;b&gt;Rust&lt;/b&gt; allow for direct memory access.&lt;br&gt;
This enables you to optimize memory usage manually, leading to faster execution times, especially in memory-intensive operations.&lt;/p&gt;

&lt;h4&gt;
  
  
  System-Level Optimizations
&lt;/h4&gt;

&lt;p&gt;The closer you are to the hardware, the more room you have for optimization. Native modules enable more efficient CPU instruction sets, cache&lt;br&gt;
optimizations, and other system-level performance improvements that are not accessible or are inefficient in a higher-level language like JavaScript.&lt;/p&gt;




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

&lt;p&gt;In this diagram, you'll notice two distinct pathways from your JavaScript code to the &lt;b&gt;System-Level APIs&lt;/b&gt;.&lt;br&gt;
One goes through the Node.js Runtime, while the other proceeds directly through a Native Module.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;b&gt;JavaScript&lt;/b&gt; Code to Node.js Runtime&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When your &lt;b&gt;JavaScript&lt;/b&gt; code needs to perform an action like reading a file or sending network requests, it calls a function that interacts with the Node.js&lt;br&gt;
Runtime. This runtime environment is a multi-layered construct, consisting of several components that each serve a specific purpose but also add&lt;br&gt;
complexity and overhead.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Event Loop&lt;/strong&gt;: The heart of Node.js's non-blocking I/O capability. It enables asynchronous operations by queuing up tasks to be executed later.&lt;br&gt;
However, it can also be a bottleneck, especially for CPU-bound tasks that can't be offloaded and must be executed sequentially.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;V8 Engine&lt;/strong&gt;: This is where your &lt;b&gt;JavaScript&lt;/b&gt; code actually gets executed. While V8 is highly optimized, it still can't match the speed of&lt;br&gt;
running precompiled code for specific tasks in various cases, adding a layer of latency.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Garbage Collection&lt;/strong&gt;: The built-in memory management mechanism can, paradoxically, introduce delays. Though it relieves you from manual&lt;br&gt;
memory management, the process of identifying and clearing unused memory can stall the execution flow.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;These layers cumulatively make the route through the Node.js Runtime slower, especially for performance-critical tasks.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Node.js Runtime to Native Module&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The second pathway moves from the Node.js Runtime directly to a Native Module, bypassing the complexities of the runtime environment. Native modules interact closely with system-level APIs and are usually written in compiled languages like &lt;b&gt;C++&lt;/b&gt; or &lt;b&gt;Rust&lt;/b&gt;.&lt;/p&gt;

&lt;p&gt;When you initiate a function call to a native module, you are essentially creating a shortcut, bypassing the event loop, the V8 engine, and garbage collection. This results in what the diagram illustrates as &lt;em&gt;"Fast API Calls"&lt;/em&gt;, leading to noticeably quicker interactions with system-level functionalities.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The Ultimate Destination: System-Level APIs&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Regardless of the route taken, the ultimate objective is to interact with System-Level APIs to execute tasks like file manipulation, network requests, or other I/O operations. The difference lies in the efficiency and speed of reaching this layer. Native modules provide a more direct, unobstructed path, making them a highly advantageous choice for performance-intensive applications.&lt;/p&gt;

&lt;p&gt;By understanding the architecture outlined in this diagram, it becomes evident why native modules can be a game-changer for certain Node.js applications. They offer a more efficient pathway to System-Level APIs, bypassing the latency-inducing layers present within the Node.js Runtime.&lt;/p&gt;




&lt;h3&gt;
  
  
  💡 Access to Low-Level APIs
&lt;/h3&gt;

&lt;p&gt;Native modules give you unparalleled access to system-level APIs, offering functionalities that are simply not available or inefficient in Node.js.&lt;br&gt;
Here's why this is crucial:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;File Systems and I/O Operations&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While Node.js provides basic file system APIs, they may not be suitable for all use-cases. For instance, you might need to access specific&lt;br&gt;
file attributes or use low-level I/O operations that the Node.js APIs don't expose.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Networking Protocols&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Need to implement a custom networking protocol or use a less common one that isn't supported by Node.js? Native modules allow you to do just that.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Hardware Interactions&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;From accessing USB ports to communicating with IoT devices, native modules can provide the low-level access you need to interface directly&lt;br&gt;
with hardware components.&lt;/p&gt;

&lt;h3&gt;
  
  
  🌍 Real-World Applications and Examples
&lt;/h3&gt;

&lt;p&gt;The theoretical benefits of native modules are compelling, but let's ground this discussion with some real-world applications where going&lt;br&gt;
native makes sense.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Data Science and Machine Learning&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Traditional data science languages like &lt;b&gt;Python&lt;/b&gt; have robust ecosystems for statistical analysis and machine learning. However, for real-time&lt;br&gt;
data processing in a Node.js application, native modules can leverage optimized &lt;b&gt;C++&lt;/b&gt; or &lt;b&gt;Rust&lt;/b&gt; libraries to perform complex calculations much faster&lt;br&gt;
than a native &lt;b&gt;JavaScript&lt;/b&gt; implementation.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Video and Audio Processing&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Real-time video and audio processing require high performance and low latency, something that native modules are particularly good at.&lt;br&gt;
By tapping into low-level APIs and system resources, native modules can handle tasks like video encoding and decoding, noise reduction, and more.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Gaming Backends&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Highly interactive, real-time gaming backends require the utmost efficiency in handling numerous simultaneous connections and rapid data exchange.&lt;br&gt;
Native modules can optimize networking protocols and data serialization techniques far beyond what's possible in plain &lt;b&gt;JavaScript&lt;/b&gt;.&lt;/p&gt;

&lt;p&gt;By understanding the benefits and real-world applications of native modules, you can make a well-informed decision on whether they are the right&lt;br&gt;
choice for your project. They offer a potent combination of performance and functionality, albeit with added complexity. However, in scenarios&lt;br&gt;
where performance, low-level access, or specialized functionalities are paramount, native modules can be a game-changing addition to your tech stack.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Anatomy of a Native Module 🛠️
&lt;/h2&gt;

&lt;p&gt;Understanding a native module's inner workings is paramount to appreciate its advantages fully. In this section, we'll dissect a native module, looking at its core components and how files are typically organized within it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Core Components of a Native Module ⚙️
&lt;/h3&gt;

&lt;p&gt;Native modules are primarily written in lower-level languages like &lt;b&gt;&lt;b&gt;C++&lt;/b&gt;&lt;/b&gt; or &lt;b&gt;&lt;b&gt;Rust&lt;/b&gt;&lt;/b&gt; and serve as a bridge between your Node.js code and system-level functionalities. Here are the core components you'll often encounter:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Binding Layer&lt;/strong&gt;: This is where the native module interacts with the Node.js runtime. It defines the functions, objects, and properties that your &lt;b&gt;JavaScript&lt;/b&gt; code can access. Typically implemented using Node's N-API or libraries like &lt;code&gt;node-gyp&lt;/code&gt; or &lt;code&gt;Neon&lt;/code&gt; for &lt;b&gt;Rust&lt;/b&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Native Code&lt;/strong&gt;: The bulk of the native module, written in a compiled language. This is the part that carries out heavy computations or interacts directly with system-level APIs. Due to being precompiled, this code is highly optimized for performance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Package Configuration&lt;/strong&gt;: Files like &lt;code&gt;binding.gyp&lt;/code&gt; for &lt;b&gt;C++&lt;/b&gt; or &lt;code&gt;Cargo.toml&lt;/code&gt; for &lt;b&gt;Rust&lt;/b&gt; specify how the module should be built. These files contain metadata and build instructions for the native module.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Exported Functions&lt;/strong&gt;: Functions that are exposed to your &lt;b&gt;JavaScript&lt;/b&gt; code, enabling interaction between the native module and your application.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Understanding these components allows for a deeper grasp of how native modules function and how they can be fine-tuned for optimal performance.&lt;/p&gt;

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

&lt;h3&gt;
  
  
  File Structure and Organization 📂
&lt;/h3&gt;

&lt;p&gt;A well-organized file structure is crucial for efficient development and maintenance of a native module. Although the specific organization can vary depending on the programming language and other requirements, you'll generally find directories for source code, package configuration, and more.&lt;/p&gt;

&lt;p&gt;For a detailed exploration of how package configurations like &lt;code&gt;binding.gyp&lt;/code&gt; play a vital role in the build process, be sure to check&lt;br&gt;
out my next blog post: &lt;a href="https://daniel-boll.me/posts/going-native-on-javascript-2" rel="noopener noreferrer"&gt;"Mastering Native Node.js Addons with node-addon-api: A Comprehensive Guide"&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>cpp</category>
      <category>rust</category>
      <category>native</category>
    </item>
    <item>
      <title>Brewing a Full-Stack Breakfast with ExpressoTS, Bun, and Elysia</title>
      <dc:creator>Daniel Boll</dc:creator>
      <pubDate>Mon, 11 Sep 2023 17:34:08 +0000</pubDate>
      <link>https://dev.to/expressots/brewing-a-full-stack-breakfast-with-expressots-bun-and-elysia-1d40</link>
      <guid>https://dev.to/expressots/brewing-a-full-stack-breakfast-with-expressots-bun-and-elysia-1d40</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Combine the power of ExpressoTS with Bun's Elysia framework in TypeScript for a mouth-watering full-stack experience.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;Welcome to a hands-on guide focused on integrating ExpressoTS, Bun, and Elysia into a full-stack TypeScript application. Let's cut to the chase and see what ingredients we'll be working with.&lt;/p&gt;

&lt;h2&gt;
  
  
  Our Ingredients
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://expresso-ts.com" rel="noopener noreferrer"&gt;&lt;strong&gt;ExpressoTS&lt;/strong&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;This TypeScript framework is designed for server-side applications. It offers flexibility in project structure and supports multiple&lt;br&gt;
architectural patterns, including MVC. If you like your applications like your coffee — robust and versatile — ExpressoTS is your go-to.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://daniel-boll.me/posts/a-first-project-with-expressots" rel="noopener noreferrer"&gt;You can also check my guide on a first project with ExpressoTS&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://bun.sh" rel="noopener noreferrer"&gt;&lt;strong&gt;Bun&lt;/strong&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;An all-in-one toolkit that brings speed and efficiency to your JavaScript and TypeScript projects.&lt;br&gt;
Think of Bun as the wholesome bread holding all your stack's ingredients together.&lt;br&gt;
It's an entire toolbox in one neat package, and it's faster than you can say "bun in the oven."&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://elysiajs.com/" rel="noopener noreferrer"&gt;&lt;strong&gt;ElysiaJS&lt;/strong&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;A Bun web framework that promises performance, simplicity, and flexibility. Designed with TypeScript in mind, Elysia is like that final&lt;br&gt;
touch of seasoning that takes your project from good to great.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;So, whether you're into French toast or a classic Eggs Benedict, the aim of this blog post is to show you how to whip up a dish that's not just full of flavor, but also robust and scalable.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Getting Started: Your First Bite of Elysia
&lt;/h1&gt;

&lt;p&gt;Now that we've set the table with the ingredients, let's start cooking. We'll begin by setting up a basic Elysia application using Bun.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Install Bun
&lt;/h2&gt;

&lt;p&gt;First, you'll need to download and install Bun. Open your terminal and run the following command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

curl &lt;span class="nt"&gt;-fsSL&lt;/span&gt; https://bun.sh/install | bash


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

&lt;/div&gt;

&lt;p&gt;This will download and install Bun on your machine, equipping you with a fast and efficient JavaScript runtime.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Create Your Elysia Project
&lt;/h2&gt;

&lt;p&gt;Once Bun is installed, it's time to create your Elysia project. Run:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

bun create elysia breakfast-ts


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

&lt;/div&gt;

&lt;p&gt;You should see a message like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

Created elysia project successfully

&lt;span class="c"&gt;# To get started, run:&lt;/span&gt;

  &lt;span class="nb"&gt;cd &lt;/span&gt;breakfast-ts
  bun run src/index.ts


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  3. Run Your Application
&lt;/h2&gt;

&lt;p&gt;Follow the instructions in the terminal message:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nb"&gt;cd &lt;/span&gt;breakfast-ts
bun run src/index.ts


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

&lt;/div&gt;

&lt;p&gt;And just like that, you should see the message, instantaneously 🌪:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

🦊 Elysia is running at localhost:3000


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

&lt;/div&gt;

&lt;p&gt;Voila! You've just whipped up your first Elysia app, hot and fresh.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Verify Your Application
&lt;/h3&gt;

&lt;p&gt;To verify Elysia's functionality, you can perform a health check using the provided endpoint. While I'll be using &lt;a href="https://httpie.io/" rel="noopener noreferrer"&gt;httpie&lt;/a&gt; for its straightforward API, you're welcome to use &lt;code&gt;curl&lt;/code&gt; if you prefer.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

http :3000


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

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;

&lt;/span&gt;&lt;span class="k"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;1.1&lt;/span&gt; &lt;span class="m"&gt;200&lt;/span&gt; &lt;span class="ne"&gt;OK&lt;/span&gt;
&lt;span class="na"&gt;Content-Length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;12&lt;/span&gt;
&lt;span class="na"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Sun, 10 Sep 2023 20:47:46 GMT&lt;/span&gt;
&lt;span class="na"&gt;content-type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;text/plain;charset=utf-8&lt;/span&gt;

Hello Elysia


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

&lt;/div&gt;
&lt;h1&gt;
  
  
  Extending Elysia: Crafting a Simple User CRUD
&lt;/h1&gt;

&lt;p&gt;With the basic setup out of the way, let's extend our Elysia app by adding some CRUD functionality for users.&lt;br&gt;
This will serve as a good starting point before we dive into more complex operations in future posts.&lt;/p&gt;
&lt;h2&gt;
  
  
  1. Run Your Application in Watch Mode
&lt;/h2&gt;

&lt;p&gt;First, stop the server if it's running. Then leverage Bun's watch mode, which will automatically reload the application&lt;br&gt;
when changes are made to the source code:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

bun run &lt;span class="nt"&gt;--watch&lt;/span&gt; src/index.ts


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  2. Add User CRUD Routes
&lt;/h2&gt;

&lt;p&gt;Now, let's define some basic CRUD operations. Open &lt;code&gt;src/index.ts&lt;/code&gt; and add to your existing code the following:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Elysia&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;elysia&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Create a user route group&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Elysia&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;group&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;user&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;app&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
  &lt;span class="nx"&gt;app&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;All users&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="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/:id&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;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`Hello, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;context&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;id&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;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Create User&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="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/:id&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;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`Update User &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;context&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;id&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;span class="k"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/:id&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;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`Delete User &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;context&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;id&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;span class="c1"&gt;// Main app&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Elysia&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello Elysia&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="nf"&gt;use&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;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&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="s2"&gt;`🦊 Elysia is running at &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;hostname&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;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;port&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;Here, we've used Elysia's &lt;code&gt;group&amp;lt;Prefix extends string = string&amp;gt;(prefix: Prefix, run: (group: Elysia&amp;lt;...&amp;gt;))&lt;/code&gt; method to bundle all user-related routes together. We've defined routes for getting all users, getting a single user by ID, creating a user, updating a user, and deleting a user.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. More Advanced Features
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note:&lt;/em&gt;&lt;/strong&gt; You can extend this basic setup in various ways. Elysia supports both simple state management within the server and more advanced&lt;br&gt;
dependency injection techniques for robust applications. Check out Elysia's documentation on&lt;br&gt;
&lt;a href="https://elysiajs.com/concept/state-decorate.html" rel="noopener noreferrer"&gt;State Decorate&lt;/a&gt; and&lt;br&gt;
&lt;a href="https://elysiajs.com/patterns/dependency-injection.html" rel="noopener noreferrer"&gt;Dependency Injection&lt;/a&gt; if you're interested.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;For the sake of this blog post, we're keeping it simple. If you are willing to expand your horizons, however, you are &lt;strong&gt;encouraged&lt;/strong&gt; to check out the&lt;br&gt;
  &lt;a href="https://daniel-boll.me/posts/a-breakfest-with-expressots-and-bun#call-to-action" rel="noopener noreferrer"&gt;&lt;strong&gt;Call to Action&lt;/strong&gt;&lt;/a&gt; section at the end of this post, where you may help the ExpressoTS community in the bun integration.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  4. Test Your User CRUD Endpoints
&lt;/h2&gt;

&lt;p&gt;After running your server, you can test each endpoint to make sure they're working as intended.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Get All Users&lt;/strong&gt;
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

http :3001/user


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

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;

&lt;/span&gt;&lt;span class="k"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;1.1&lt;/span&gt; &lt;span class="m"&gt;200&lt;/span&gt; &lt;span class="ne"&gt;OK&lt;/span&gt;
&lt;span class="na"&gt;Content-Length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;9&lt;/span&gt;
&lt;span class="na"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Sun, 10 Sep 2023 20:47:46 GMT&lt;/span&gt;
&lt;span class="na"&gt;content-type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;text/plain;charset=utf-8&lt;/span&gt;

All users


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Get a Single User&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Replace &lt;code&gt;{id}&lt;/code&gt; with the ID of the user you're interested in.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

http :3001/user/42


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

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;

&lt;/span&gt;&lt;span class="k"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;1.1&lt;/span&gt; &lt;span class="m"&gt;200&lt;/span&gt; &lt;span class="ne"&gt;OK&lt;/span&gt;
&lt;span class="na"&gt;Content-Length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;11&lt;/span&gt;
&lt;span class="na"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Sun, 10 Sep 2023 20:47:46 GMT&lt;/span&gt;
&lt;span class="na"&gt;content-type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;text/plain;charset=utf-8&lt;/span&gt;

Hello, 42


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Create a User&lt;/strong&gt;
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

http POST :3001/user


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

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;

&lt;/span&gt;&lt;span class="k"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;1.1&lt;/span&gt; &lt;span class="m"&gt;200&lt;/span&gt; &lt;span class="ne"&gt;OK&lt;/span&gt;
&lt;span class="na"&gt;Content-Length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;11&lt;/span&gt;
&lt;span class="na"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Sun, 10 Sep 2023 20:47:46 GMT&lt;/span&gt;
&lt;span class="na"&gt;content-type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;text/plain;charset=utf-8&lt;/span&gt;

Create User


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Update a User&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Again, replace &lt;code&gt;{id}&lt;/code&gt; with the ID of the user you want to update.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

http PUT :3001/user/42


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

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;

&lt;/span&gt;&lt;span class="k"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;1.1&lt;/span&gt; &lt;span class="m"&gt;200&lt;/span&gt; &lt;span class="ne"&gt;OK&lt;/span&gt;
&lt;span class="na"&gt;Content-Length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;16&lt;/span&gt;
&lt;span class="na"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Sun, 10 Sep 2023 20:47:46 GMT&lt;/span&gt;
&lt;span class="na"&gt;content-type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;text/plain;charset=utf-8&lt;/span&gt;

Update User 42


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Delete a User&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;And one last time, replace &lt;code&gt;{id}&lt;/code&gt; with the ID of the user you want to delete.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

http DELETE :3001/user/42


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

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;

&lt;/span&gt;&lt;span class="k"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;1.1&lt;/span&gt; &lt;span class="m"&gt;200&lt;/span&gt; &lt;span class="ne"&gt;OK&lt;/span&gt;
&lt;span class="na"&gt;Content-Length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;16&lt;/span&gt;
&lt;span class="na"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Sun, 10 Sep 2023 20:47:46 GMT&lt;/span&gt;
&lt;span class="na"&gt;content-type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;text/plain;charset=utf-8&lt;/span&gt;

Delete User 42


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

&lt;/div&gt;

&lt;p&gt;Now you've successfully tested all of your user CRUD operations. It's like a full-course breakfast — everything is present and accounted for!&lt;/p&gt;

&lt;h2&gt;
  
  
  Diving into the Heart of the Matter: &lt;strong&gt;Reflection&lt;/strong&gt; and &lt;strong&gt;Decorators&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In programming, reflection is a mechanism that allows you to inspect and manipulate program elements like classes and objects at runtime. In other words, reflection enables a program to observe its own structure, similar to how you can observe your own reflection in the mirror. This allows for greater dynamic behavior, enabling more powerful and flexible constructs like decorators.&lt;/p&gt;

&lt;h1&gt;
  
  
  Dive deeper @ &lt;a href="https://daniel-boll.me/posts/a-breakfest-with-expressots-and-bun#diving-into-the-heart-of-the-matter-reflection-and-decorators" rel="noopener noreferrer"&gt;daniel-boll.me&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;If you are interested in the stuff you can achieve with reflection make sure to check out the full blog at &lt;a href="https://daniel-boll.me/posts/a-breakfest-with-expressots-and-bun#diving-into-the-heart-of-the-matter-reflection-and-decorators" rel="noopener noreferrer"&gt;daniel-boll.me&lt;/a&gt; for much more content.&lt;/p&gt;

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

</description>
      <category>expressots</category>
      <category>typescript</category>
      <category>bunjs</category>
      <category>elysiajs</category>
    </item>
    <item>
      <title>A first project with ExpressoTS</title>
      <dc:creator>Daniel Boll</dc:creator>
      <pubDate>Sun, 27 Aug 2023 17:35:21 +0000</pubDate>
      <link>https://dev.to/expressots/a-first-project-with-expressots-30e8</link>
      <guid>https://dev.to/expressots/a-first-project-with-expressots-30e8</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://expresso-ts.com/"&gt;ExpressoTS&lt;/a&gt; is a new developer-friendly TypeScript framework for Server-Side Applications. It's currently built on top of &lt;a href="https://expressjs.com/"&gt;Express&lt;/a&gt;, easy to get a new developer on board, light and easy project structure, two different project structure supported (opinionated and non opinionated version), supports MVC, non MVC, architecture. The opinionated template was built on top of clean architecture, you will see concepts embedded in the opinionated template such as entities, useCases, repositories and providers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up Your First ExpressoTS Project
&lt;/h2&gt;

&lt;p&gt;Ah, the first step to any great journey in the world of coding—a proper setup. Trust me, nobody wants to get lost before even starting the adventure. So, let's cut the chit-chat and dive right in.&lt;/p&gt;

&lt;h3&gt;
  
  
  Installation of ExpressoTS CLI
&lt;/h3&gt;

&lt;p&gt;You've got two routes here, and the destination is the same, a functional ExpressoTS environment. Your first option is to install the ExpressoTS CLI globally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pnpm i &lt;span class="nt"&gt;-g&lt;/span&gt; @expressots/cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Got limited commitment issues? No worries, you can also use &lt;code&gt;dlx&lt;/code&gt; to run the CLI without installing it globally. Ah, the wonders of a one-night stand with a CLI!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pnpx @expressots/cli new expressots-first-project
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Configuration Wizard
&lt;/h3&gt;

&lt;p&gt;After running the command, you're greeted by a friendly (albeit text-based) wizard 🧙‍♂️.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;[&lt;/span&gt;🐎 Expressots]

? Project name expressots-first-project
? Package manager pnpm
? Select a template Non-Opinionated :: A simple ExpressoTS project.
? Do you want to create this project? Yes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fill out the form wisely but don't overthink it. For this tutorial, I'm going with the "Non-Opinionated" template because, it will give us a shallower learning curve in the start.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Comfy in Your New ExpressoTS Home 🏡
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Navigating to Your Project
&lt;/h3&gt;

&lt;p&gt;So you've set up your new ExpressoTS project. Awesome! Time to get inside the engine room and take a look under the hood.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;expressots-first-project
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You're now in the root folder, and if you're curious about what comes packed by default, run a quick &lt;code&gt;tree&lt;/code&gt; command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;@expressots/tests/expressots-first-project via  v16.19.0
❯ tree &lt;span class="nt"&gt;-I&lt;/span&gt; node_modules &lt;span class="nt"&gt;-a&lt;/span&gt;
&lt;span class="nb"&gt;.&lt;/span&gt;
├── .eslintrc.js
├── expressots.config.ts
├── .gitignore
├── jest.config.ts
├── package.json
├── pnpm-lock.yaml
├── .prettierrc
├── README.md
├── src
│   ├── app.container.ts
│   ├── app.controller.ts
│   ├── app.module.ts
│   ├── app.usecase.ts
│   └── main.ts
├── &lt;span class="nb"&gt;test&lt;/span&gt;
│   └── app.usecase.spec.ts
├── tsconfig.build.json
└── tsconfig.json

3 directories, 16 files
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There you go! These are the files you'll be living with.&lt;/p&gt;

&lt;h3&gt;
  
  
  Customizing Your Prettier Preferences
&lt;/h3&gt;

&lt;p&gt;You've got your own coding style—don't we all? You can tweak the &lt;code&gt;.prettierrc&lt;/code&gt; file to your heart's content.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"singleQuote"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"trailingComma"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"all"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"endOfLine"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"auto"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"tabWidth"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Let's Take a Quick Tour of &lt;strong&gt;package.json&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;A glance at the &lt;code&gt;scripts&lt;/code&gt; section in &lt;code&gt;package.json&lt;/code&gt; tells you all you need to know to get things up and running.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;❯ &lt;span class="nb"&gt;cat &lt;/span&gt;package.json | jq &lt;span class="s2"&gt;".scripts"&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="s2"&gt;"prebuild"&lt;/span&gt;: &lt;span class="s2"&gt;"rm -rf ./dist"&lt;/span&gt;,
  &lt;span class="s2"&gt;"build"&lt;/span&gt;: &lt;span class="s2"&gt;"tsc -p tsconfig.build.json"&lt;/span&gt;,
  &lt;span class="s2"&gt;"dev"&lt;/span&gt;: &lt;span class="s2"&gt;"tsnd ./src/main.ts"&lt;/span&gt;,
  &lt;span class="s2"&gt;"prod"&lt;/span&gt;: &lt;span class="s2"&gt;"node ./dist/main.js"&lt;/span&gt;,
  &lt;span class="s2"&gt;"test"&lt;/span&gt;: &lt;span class="s2"&gt;"jest"&lt;/span&gt;,
  &lt;span class="s2"&gt;"test:watch"&lt;/span&gt;: &lt;span class="s2"&gt;"jest --watchAll"&lt;/span&gt;,
  &lt;span class="s2"&gt;"test:cov"&lt;/span&gt;: &lt;span class="s2"&gt;"jest --coverage"&lt;/span&gt;,
  &lt;span class="s2"&gt;"format"&lt;/span&gt;: &lt;span class="s2"&gt;"prettier --write &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;src/**/*.ts&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;test/**/*.ts&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;,
  &lt;span class="s2"&gt;"lint"&lt;/span&gt;: &lt;span class="s2"&gt;"eslint &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;src/**/*.ts&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt; --fix"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, you've got your usual suspects: build, dev, test, and more.&lt;/p&gt;

&lt;h3&gt;
  
  
  Format All The Things!
&lt;/h3&gt;

&lt;p&gt;Before diving into development, let's keep it neat. The &lt;code&gt;format&lt;/code&gt; script will handle that.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pnpm format
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Running in Dev Mode
&lt;/h3&gt;

&lt;p&gt;And finally, the moment you've been waiting for—fire up the dev server and see your app come to life!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;@expressots/tests/expressots-first-project via  v16.19.0
❯ pnpm dev

&lt;span class="o"&gt;[&lt;/span&gt;INFO] ts-node-dev ver. 2.0.0 &lt;span class="o"&gt;(&lt;/span&gt;using ts-node ver. 10.9.1, typescript ver. 4.9.5&lt;span class="o"&gt;)&lt;/span&gt;
Application version not provided is running on port 3000 - Environment: development
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Making Your First Request in ExpressoTS 🌐
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Time for a Little Hello!
&lt;/h3&gt;

&lt;p&gt;You've been through the house tour, you've feng shui'd your &lt;code&gt;.prettierrc&lt;/code&gt; and got your scripts all figured out. Now what? Well, how about actually seeing your app in action?&lt;/p&gt;

&lt;h3&gt;
  
  
  Using HTTPie for Your First GET Request
&lt;/h3&gt;

&lt;p&gt;For this demonstration, we're going to use &lt;a href="https://httpie.io/"&gt;HTTPie&lt;/a&gt; — the &lt;code&gt;cURL&lt;/code&gt; for the 21st century. But like, way more readable. Here's how to send your first GET request to &lt;code&gt;http://localhost:3000&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;@expressots/tests/expressots-first-project via  v16.19.0
❯ http :3000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Bam!&lt;/em&gt; You should see a response like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;HTTP/1.1 200 OK
...
Hello Expresso TS!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Congrats!&lt;/strong&gt; You just made your server say hello.&lt;/p&gt;

&lt;h2&gt;
  
  
  Anatomy of the "Hello Expresso TS!" 🦴
&lt;/h2&gt;

&lt;p&gt;Alright, let's dissect that &lt;code&gt;"Hello Expresso TS!"&lt;/code&gt; message. How does this simple string pass through layers of TypeScript files to make it to your browser? Spoiler: &lt;em&gt;It's not magic; it's just well-structured code.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The Starting Point: &lt;strong&gt;src/main.ts&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This is where the baton is picked up. Here, we import the essential parts from ExpressoTS and set up the initial application instance. Simple enough.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;reflect-metadata&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;AppInstance&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ServerEnvironment&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@expressots/core&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./app.container&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;bootstrap&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;AppInstance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;AppInstance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ServerEnvironment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Development&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;bootstrap&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The Container: &lt;strong&gt;src/app.container.ts&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Think of this as the backstage, where everyone gets ready for the show. It's where the application container is configured with your custom modules.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;AppContainer&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@expressots/core&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;AppModule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./app.module&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;appContainer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;AppContainer&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;container&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;appContainer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;AppModule&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The Module: &lt;strong&gt;src/app.module.ts&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Modules in ExpressoTS group related functionalities. Here, it's as simple as importing the &lt;code&gt;AppController&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;CreateModule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@expressots/core&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;AppController&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./app.controller&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;AppModule&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;CreateModule&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;AppController&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;AppModule&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The Controller: &lt;strong&gt;src/app.controller.ts&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This is the conductor of our orchestra. It's responsible for handling HTTP requests and directing traffic. In this case, it's just saying, &lt;code&gt;"Hello Expresso TS!"&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;BaseController&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;httpGet&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;inversify-express-utils&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Response&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;AppUseCase&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./app.usecase&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="nd"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;AppController&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;BaseController&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;appUseCase&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;AppUseCase&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;app-controller&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="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;httpGet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nx"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(@&lt;/span&gt;&lt;span class="nd"&gt;response&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;appUseCase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;execute&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;h3&gt;
  
  
  The Use Case: &lt;strong&gt;src/app.usecase.ts&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Here's where the actual &lt;code&gt;"Hello Expresso TS!"&lt;/code&gt; lives.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;provide&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;inversify-binding-decorators&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="nd"&gt;provide&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;AppUseCase&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;AppUseCase&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello Expresso TS!&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  "Hello, Who?" Changing the Default Response 🖊️
&lt;/h2&gt;

&lt;p&gt;Got bored of the usual &lt;code&gt;"Hello Expresso TS!"&lt;/code&gt;? Let's give it a personal touch. To do that, we only need to venture into the &lt;code&gt;src/app.usecase.ts&lt;/code&gt; file. See, this is the beauty of a well-structured codebase; you don't have to jump through hoops to make a simple change.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Tweak: &lt;strong&gt;src/app.usecase.ts&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;One line change. That's it. Here we just swap out the text to &lt;code&gt;"Hello from &amp;lt;Daniel::Boll&amp;gt;"&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;provide&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;AppUseCase&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;AppUseCase&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello from &amp;lt;Daniel::Boll&amp;gt;&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The Reload: Auto-refresh FTW
&lt;/h3&gt;

&lt;p&gt;As soon as you save that change, the development server detects this update and reloads itself. No manual effort required. Ah, the joys of modern development.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;[&lt;/span&gt;INFO] Restarting: /../@expressots/tests/expressots-first-project/src/app.usecase.ts has been modified
Application version not provided is running on port 3000 - Environment: development
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The Result: Let's Talk to the Server Again
&lt;/h3&gt;

&lt;p&gt;Run the command, and voila! The updated greeting is now served hot, right from your server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Hello from &amp;lt;Daniel::Boll&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Dive deeper
&lt;/h2&gt;

&lt;p&gt;If you are interested in more stuff you can do in this simple ExpressoTS project make sure to check out the full blog at &lt;a href="https://daniel-boll.me/posts/a-first-project-with-expressots"&gt;daniel-boll.me&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
      <category>expressots</category>
      <category>restapi</category>
    </item>
  </channel>
</rss>
