<?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: Souhail Brahmi</title>
    <description>The latest articles on DEV Community by Souhail Brahmi (@souhailxedits).</description>
    <link>https://dev.to/souhailxedits</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%2F1624722%2Fd7f964c4-34c2-4afc-af2e-762e00af2358.png</url>
      <title>DEV Community: Souhail Brahmi</title>
      <link>https://dev.to/souhailxedits</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/souhailxedits"/>
    <language>en</language>
    <item>
      <title>Docker Run vs Docker Compose: Which One Should You Use for Container Management?</title>
      <dc:creator>Souhail Brahmi</dc:creator>
      <pubDate>Thu, 08 Aug 2024 15:16:43 +0000</pubDate>
      <link>https://dev.to/souhailxedits/docker-run-vs-docker-compose-which-one-should-you-use-for-container-management-1g1j</link>
      <guid>https://dev.to/souhailxedits/docker-run-vs-docker-compose-which-one-should-you-use-for-container-management-1g1j</guid>
      <description>&lt;p&gt;&lt;em&gt;In the world of containerization, Docker has emerged as a go-to tool for developers and operations teams alike. But when it comes to managing and running containers, you might find yourself wondering whether to use docker run or Docker Compose. Both are powerful in their own right, but they serve different purposes and are best suited for specific scenarios.&lt;br&gt;
In this post, we’ll dive deep into the differences between docker run and Docker Compose, exploring how each one works, their benefits, and when to choose one over the other. By the end, you’ll have a clear understanding of which tool to use depending on your needs.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is docker run?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before diving into comparisons, let’s break down what docker run actually does. The docker run command is the most basic and essential command in Docker. It’s used to create and start a container from an image. Think of it as the fundamental way to launch an individual container.&lt;/p&gt;

&lt;p&gt;Key Features of docker run:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Simplicity:&lt;/strong&gt; With docker run, you’re starting a single container. This command is straightforward and perfect for quick tests or when working with individual containers.&lt;br&gt;
&lt;strong&gt;2. Customizability:&lt;/strong&gt; You can pass various flags and options to docker run to customize the behavior of the container. For example, you can expose ports, mount volumes, set environment variables, and more.&lt;br&gt;
&lt;strong&gt;3. Granular Control:&lt;/strong&gt; If you need fine-grained control over a single container’s behavior, docker run gives you that flexibility.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example Usage:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -d -p 80:80 --name mynginx nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, docker run is used to start an Nginx container in detached mode (&lt;strong&gt;-d&lt;/strong&gt;), map port 80 of the container to port &lt;strong&gt;80&lt;/strong&gt; on the host machine (&lt;strong&gt;-p 80:80&lt;/strong&gt;), and name the container mynginx.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Docker Compose?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now that we’ve covered docker run, let’s move on to Docker Compose. Docker Compose is a tool designed to help you define and manage multi-container Docker applications. It uses a &lt;strong&gt;YAML&lt;/strong&gt; file to configure your application’s services, networks, and volumes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features of Docker Compose:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Multi-Container Management:&lt;/strong&gt; Docker Compose shines when you need to manage multiple containers that work together as part of an application stack. Instead of manually starting each container, you can define them all in a single YAML file.&lt;br&gt;
&lt;strong&gt;Service-Oriented:&lt;/strong&gt; In Docker Compose, you define each container as a "service." This approach allows you to manage the entire stack as a cohesive unit, which is especially useful in complex applications.&lt;br&gt;
&lt;strong&gt;Environment Management:&lt;/strong&gt; Docker Compose allows you to define environment variables, networks, and volumes in a centralized way. This makes it easier to manage environments, especially across different stages like development, testing, and production.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example Usage:&lt;/strong&gt;&lt;br&gt;
Here’s a simple docker-compose.yml file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: '3'
services:
  web:
    image: nginx
    ports:
      - "80:80"
  redis:
    image: redis
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Running docker-compose up will start both the Nginx and Redis containers, automatically setting up the required networking between them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Docker Run&lt;/strong&gt; vs &lt;strong&gt;Docker Compose&lt;/strong&gt;: A Head-to-Head Comparison&lt;br&gt;
Now that you know what docker run and Docker Compose are, let’s compare them directly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Complexity of Setup:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;docker run:&lt;/strong&gt; Best for simple, single-container scenarios. It requires you to manually set up and start each container, which can become cumbersome as the number of containers grows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Docker Compose:&lt;/strong&gt; Ideal for complex, multi-container applications. It simplifies the process of managing related containers by defining them in a single YAML file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Ease of Use:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;docker run:&lt;/strong&gt; Easier to use for quick, one-off container launches. However, managing multiple containers this way can get tedious.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Docker Compose:&lt;/strong&gt; More user-friendly for applications with multiple containers. You can bring up the entire stack with a single command (&lt;strong&gt;docker-compose up&lt;/strong&gt;), which is much more convenient.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Scaling:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;docker run:&lt;/strong&gt; Scaling containers manually requires you to launch additional instances using separate docker run commands.&lt;br&gt;
&lt;strong&gt;Docker Compose:&lt;/strong&gt; Supports scaling out services with a simple command (docker-compose up --scale). This is particularly useful in micro-services architectures.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Environment Management:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;docker run:&lt;/strong&gt; Environment variables need to be passed manually or through a &lt;strong&gt;.env&lt;/strong&gt; file, but there’s no native support for managing multiple environments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Docker Compose:&lt;/strong&gt; You can easily manage different environments (e.g., &lt;strong&gt;dev&lt;/strong&gt;, &lt;strong&gt;staging&lt;/strong&gt;, &lt;strong&gt;production&lt;/strong&gt;) by using different &lt;strong&gt;YAML&lt;/strong&gt; files or overriding configurations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Networking:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;docker run:&lt;/strong&gt; Networking between containers needs to be set up manually, which can be tricky.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Docker Compose:&lt;/strong&gt; Automatically manages networking between services, making it easier to set up inter-container communication.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When to Use docker run&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Single Container Scenarios:&lt;/strong&gt; If you’re just spinning up a single container, docker run is the fastest and simplest option.&lt;br&gt;
Quick Tests: For quick experiments or tests where you don’t need the overhead of managing multiple containers, docker run is perfect.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Custom Configurations:&lt;/strong&gt; When you need granular control over a container’s startup configuration, docker run gives you the flexibility you need.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When to Use Docker Compose&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Multi-Container Applications:&lt;/strong&gt; If your application consists of multiple containers that need to work together, Docker Compose is your best bet.&lt;br&gt;
&lt;strong&gt;Development and Testing:&lt;/strong&gt; Docker Compose simplifies the process of setting up consistent development and testing environments.&lt;br&gt;
Micro-services Architectures: When working with micro-services, Docker Compose makes it easier to manage and orchestrate multiple containers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt; Choose the Right Tool for the Job&lt;br&gt;
So, which one should you use—docker run or Docker Compose? The answer, as you might expect, depends on your specific needs.&lt;/p&gt;

&lt;p&gt;Use docker run for simpler, single-container scenarios where you need quick results without the complexity of managing multiple services.&lt;/p&gt;

&lt;p&gt;Choose Docker Compose when dealing with complex, multi-container applications that require a cohesive, orchestrated environment.&lt;br&gt;
By understanding the strengths and limitations of each tool, you can make an informed decision that will streamline your container management process.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>containers</category>
      <category>node</category>
      <category>devops</category>
    </item>
    <item>
      <title>Setting Titles Dynamically with Next.js Metadata</title>
      <dc:creator>Souhail Brahmi</dc:creator>
      <pubDate>Tue, 09 Jul 2024 06:50:01 +0000</pubDate>
      <link>https://dev.to/souhailxedits/setting-titles-dynamically-with-nextjs-metadata-4hog</link>
      <guid>https://dev.to/souhailxedits/setting-titles-dynamically-with-nextjs-metadata-4hog</guid>
      <description>&lt;p&gt;Next.js has introduced a new App Router that provides more flexibility and structure to manage routes and metadata. This new approach simplifies dynamic title setting and other metadata for your application. In this blog post, we'll explore how to set titles dynamically using the App Router in Next.js.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Dynamic Titles Matter&lt;/strong&gt;&lt;br&gt;
Dynamic titles enhance the user experience by providing relevant information for each page. They also improve SEO, making it easier for search engines to index your pages accurately. This is particularly important for content-heavy websites like blogs, e-commerce stores, and news sites where each page has unique content.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Getting Started with the App Router&lt;/strong&gt;&lt;br&gt;
-First, ensure you have a Next.js project set up with the App Router. If not, you can create one by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-next-app@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-Navigate to your project directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd your-nextjs-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ensure your Next.js version supports the App Router. The App Router is available from Next.js 12.1 onwards.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using Metadata in App Router&lt;/strong&gt;&lt;br&gt;
Next.js App Router uses a special metadata property to handle the &lt;/p&gt; tags, including the title. This method allows you to define metadata in your page components directly.

&lt;p&gt;&lt;strong&gt;1.Create Your App Layout:&lt;/strong&gt;&lt;br&gt;
In the app directory, create a layout file (e.g., app/layout.js):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// app/layout.js
import './globals.css';

export const metadata = {
  title: 'Default Title - My Next.js App',
  description: 'Default description for my Next.js app',
};

export default function RootLayout({ children }) {
  return (
    &amp;lt;html lang="en"&amp;gt;
      &amp;lt;head /&amp;gt;
      &amp;lt;body&amp;gt;{children}&amp;lt;/body&amp;gt;
    &amp;lt;/html&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2.Set Dynamic Titles in Page Components:&lt;/strong&gt;&lt;br&gt;
Each page component can override the default metadata by exporting a metadata object. Here's an example for a home page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// app/page.js
export const metadata = {
  title: 'Home Page - My Awesome Website',
  description: 'Welcome to the home page of my awesome website',
};

export default function HomePage() {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;Welcome to My Awesome Website&amp;lt;/h1&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3.Dynamic Titles Based on Props:&lt;/strong&gt;&lt;br&gt;
For more dynamic use cases, such as blog posts or product pages, you can set the title based on props. Here’s an example for a blog post page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// app/posts/[id]/page.js
import { useRouter } from 'next/router';

export async function generateMetadata({ params }) {
  const { id } = params;
  const res = await fetch(`https://api.example.com/posts/${id}`);
  const post = await res.json();

  return {
    title: `${post.title} - My Blog`,
    description: post.summary,
  };
}

export default function BlogPost({ params }) {
  const { id } = params;
  const [post, setPost] = React.useState(null);

  React.useEffect(() =&amp;gt; {
    fetch(`https://api.example.com/posts/${id}`)
      .then((response) =&amp;gt; response.json())
      .then((data) =&amp;gt; setPost(data));
  }, [id]);

  if (!post) return &amp;lt;div&amp;gt;Loading...&amp;lt;/div&amp;gt;;

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;{post.title}&amp;lt;/h1&amp;gt;
      &amp;lt;p&amp;gt;{post.content}&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Advanced Metadata Handling&lt;/strong&gt;&lt;br&gt;
For more complex scenarios, you might want to set metadata dynamically at a global level or use custom hooks. The following example demonstrates a custom hook for managing metadata:&lt;br&gt;
&lt;strong&gt;1.Create a Custom Hook:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// hooks/useMetadata.js
import { useEffect } from 'react';
import { useRouter } from 'next/router';

const useMetadata = (title, description) =&amp;gt; {
  const router = useRouter();

  useEffect(() =&amp;gt; {
    document.title = title;
    const metaDescription = document.querySelector('meta[name="description"]');
    if (metaDescription) {
      metaDescription.setAttribute('content', description);
    } else {
      const meta = document.createElement('meta');
      meta.name = 'description';
      meta.content = description;
      document.head.appendChild(meta);
    }
  }, [title, description, router.pathname]);
};

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2.Use the Hook in a Component:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// app/page.js
import useMetadata from '../hooks/useMetadata';

export default function HomePage() {
  useMetadata('Home Page - My Awesome Website', 'Welcome to the home page of my awesome website');

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;Welcome to My Awesome Website&amp;lt;/h1&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Setting dynamic titles and metadata in Next.js using the App Router is straightforward and powerful. By leveraging the metadata property and custom hooks, you can ensure that each page in your application has the correct metadata, improving both SEO and user experience. Experiment with different strategies to see what works best for your use case, and remember that thoughtful metadata can significantly impact your site's visibility and user engagement.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>seo</category>
      <category>web</category>
      <category>learning</category>
    </item>
    <item>
      <title>Getting Started with NestJS and TypeORM: A Beginner's Guide</title>
      <dc:creator>Souhail Brahmi</dc:creator>
      <pubDate>Fri, 14 Jun 2024 08:47:20 +0000</pubDate>
      <link>https://dev.to/souhailxedits/getting-started-with-nestjs-and-typeorm-a-beginners-guide-ggc</link>
      <guid>https://dev.to/souhailxedits/getting-started-with-nestjs-and-typeorm-a-beginners-guide-ggc</guid>
      <description>&lt;p&gt;Hey &lt;em&gt;everyone&lt;/em&gt;! 👋 If you're looking to build scalable and maintainable server-side applications with Node.js, NestJS is a fantastic framework to dive into. Combined with TypeORM for database interactions, you can create robust and type-safe applications with ease. In this guide, we'll walk through setting up a simple NestJS project with TypeORM.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why NestJS and TypeORM?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NestJS&lt;/strong&gt;&lt;br&gt;
NestJS is a progressive Node.js framework built with TypeScript that leverages the robust features of Angular to provide a reliable structure for building server-side applications. Its modular architecture makes it easy to manage and scale large applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TypeORM&lt;/strong&gt;&lt;br&gt;
TypeORM is an ORM (Object-Relational Mapper) for TypeScript and JavaScript (ES7, ES6, ES5). It supports many databases and allows you to interact with your database using TypeScript's powerful type system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setting Up Your Environment&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;br&gt;
Before we start, make sure you have Node.js and npm installed. You can download them from Node.js official website.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Create a New NestJS Project&lt;/strong&gt;&lt;br&gt;
First, we'll create a new NestJS project using the Nest CLI. If you don't have the Nest CLI installed, you can install it globally:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Now, create a new project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nest new my-nestjs-project
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Install TypeORM and Dependencies&lt;/strong&gt;&lt;br&gt;
Next, we need to install TypeORM and the database driver we'll use. For this example, we'll use SQLite because it's simple and doesn't require any setup.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3: Configure TypeORM&lt;/strong&gt;&lt;br&gt;
We need to configure TypeORM in our NestJS project. Open src/app.module.ts and update it to include TypeORM configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
  imports: [
    TypeOrmModule.forRoot({
      type: 'sqlite',
      database: 'database.sqlite',
      entities: [__dirname + '/**/*.entity{.ts,.js}'],
      synchronize: true,
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4: Create an Entity&lt;/strong&gt;&lt;br&gt;
Entities are the core of TypeORM. They represent the tables in your database. Let's create a simple User entity.&lt;/p&gt;

&lt;p&gt;Create a new directory called entities inside the src directory, and then create a file named user.entity.ts inside the entities directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';

@Entity()
export class User {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  name: string;

  @Column()
  email: string;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 5: Create a User Module and Service&lt;/strong&gt;&lt;br&gt;
To keep our code modular, we will create a user module and a corresponding service to handle our user-related logic.&lt;/p&gt;

&lt;p&gt;Generate a new module and service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nest generate module users
nest generate service users
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, update 'src/users/users.module.ts' to include TypeORM for our User entity:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UsersService } from './users.service';
import { User } from '../entities/user.entity';

@Module({
  imports: [TypeOrmModule.forFeature([User])],
  providers: [UsersService],
  exports: [UsersService],
})
export class UsersModule {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 6: Implement the Users Service&lt;/strong&gt;&lt;br&gt;
Open src/users/users.service.ts and implement basic CRUD operations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { User } from '../entities/user.entity';

@Injectable()
export class UsersService {
  constructor(
    @InjectRepository(User)
    private usersRepository: Repository&amp;lt;User&amp;gt;,
  ) {}

  findAll(): Promise&amp;lt;User[]&amp;gt; {
    return this.usersRepository.find();
  }

  findOne(id: number): Promise&amp;lt;User&amp;gt; {
    return this.usersRepository.findOneBy({ id });
  }

  create(user: User): Promise&amp;lt;User&amp;gt; {
    return this.usersRepository.save(user);
  }

  async remove(id: number): Promise&amp;lt;void&amp;gt; {
    await this.usersRepository.delete(id);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 7: Create a Users Controller&lt;/strong&gt;&lt;br&gt;
Generate a controller for users:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nest generate controller users
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open src/users/users.controller.ts and set up the endpoints:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Controller, Get, Post, Body, Param, Delete } from '@nestjs/common';
import { UsersService } from './users.service';
import { User } from '../entities/user.entity';

@Controller('users')
export class UsersController {
  constructor(private readonly usersService: UsersService) {}

  @Get()
  findAll(): Promise&amp;lt;User[]&amp;gt; {
    return this.usersService.findAll();
  }

  @Get(':id')
  findOne(@Param('id') id: string): Promise&amp;lt;User&amp;gt; {
    return this.usersService.findOne(+id);
  }

  @Post()
  create(@Body() user: User): Promise&amp;lt;User&amp;gt; {
    return this.usersService.create(user);
  }

  @Delete(':id')
  remove(@Param('id') id: string): Promise&amp;lt;void&amp;gt; {
    return this.usersService.remove(+id);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 8: Integrate Users Module&lt;/strong&gt;&lt;br&gt;
Finally, integrate the UsersModule into our AppModule. Open src/app.module.ts and update it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UsersModule } from './users/users.module';

@Module({
  imports: [
    TypeOrmModule.forRoot({
      type: 'sqlite',
      database: 'database.sqlite',
      entities: [__dirname + '/**/*.entity{.ts,.js}'],
      synchronize: true,
    }),
    UsersModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})

export class AppModule {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Running the Application&lt;/strong&gt;&lt;br&gt;
Now that everything is set up, you can run your application:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Your NestJS server should be running, and you can start interacting with your API. Try making some requests to the /users endpoint using Postman or any other API client to see your CRUD operations in action.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Congratulations! 🎉 You've just set up a basic NestJS application with TypeORM and implemented CRUD operations for a User entity. From here, you can expand your application by adding more entities, services, and controllers as needed.&lt;/p&gt;

&lt;p&gt;NestJS and TypeORM provide a powerful combination for building scalable and maintainable applications. Keep exploring the NestJS and TypeORM documentation to unlock their full potential.&lt;/p&gt;

&lt;p&gt;Happy coding! 🚀&lt;/p&gt;

</description>
      <category>nestjs</category>
      <category>typeorm</category>
      <category>webdev</category>
      <category>apigateway</category>
    </item>
  </channel>
</rss>
