<?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: Shreyas Hupare</title>
    <description>The latest articles on DEV Community by Shreyas Hupare (@medianova).</description>
    <link>https://dev.to/medianova</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%2F2858965%2F9c320dce-c6e7-4610-96d0-ceb01bc74689.png</url>
      <title>DEV Community: Shreyas Hupare</title>
      <link>https://dev.to/medianova</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/medianova"/>
    <language>en</language>
    <item>
      <title>Prompt Engineering</title>
      <dc:creator>Shreyas Hupare</dc:creator>
      <pubDate>Tue, 17 Jun 2025 17:55:34 +0000</pubDate>
      <link>https://dev.to/medianova/prompt-engineering-1nfg</link>
      <guid>https://dev.to/medianova/prompt-engineering-1nfg</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Garbage In, Garbage Out!&lt;br&gt;
"The quality of your question decides the quality of ai's answer."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What is Prompt Engineering? Why it matters ?
&lt;/h2&gt;

&lt;p&gt;A prompt means giving instructions to an AI model, right? &lt;br&gt;
Well, not exactly. You can call it a prompt, but that alone doesn't make it prompt engineering. The real magic lies in how you ask the question. The output depends entirely on that.&lt;br&gt;
So, why call it engineering? Because it's not just asking questions - it's learning how the model responds, testing different instructions, refining your approach, and building better results over time. That's an iterative, structured process - just like engineering.&lt;br&gt;
So basically, prompt engineering is all about tweaking and refining your input to get the most accurate and useful output from an AI model.&lt;/p&gt;

&lt;h2&gt;
  
  
  Golden Rule #Don't Trust the Model Blindly
&lt;/h2&gt;

&lt;p&gt;Let's get one thing straight: AI is a tool, not a truth machine.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It can hallucinate facts.&lt;/li&gt;
&lt;li&gt;It can make assumptions.&lt;/li&gt;
&lt;li&gt;It might sound confident and still be wrong.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So never expect it to do your job. Use it as a helpful assistant - but always verify what it gives you. It never supposed to give right answers. &lt;/p&gt;

&lt;h2&gt;
  
  
  Simple Checklist to improve your prompt
&lt;/h2&gt;

&lt;p&gt;🧑‍🎓 1. &lt;strong&gt;Set the Persona&lt;/strong&gt;&lt;br&gt;
Tell the model who to become.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"You are a senior nodeJS developer working on NestJs Framework."&lt;br&gt;
"You are a product manager writing a user story."&lt;br&gt;
Why? Because it helps the model adopt the right tone, terminology, and context.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;🙋‍♂️ 2. &lt;strong&gt;Say Who You Are &amp;amp; What you are trying to achieve&lt;/strong&gt;&lt;br&gt;
Let the model know your role too.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"I'm a beginner learning nodeJs and building simple to-do list application."&lt;br&gt;
"I run a small business and want to automate emails."&lt;br&gt;
This builds alignment and helps it tailor answers to your level.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;📦 3. &lt;strong&gt;Give Clear Context&lt;/strong&gt;&lt;br&gt;
Don't leave it guessing. Do half job for AI.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;❌ "Fix this code."&lt;br&gt;
✅ "This is a React component giving a 'TypeError' on button click. Can you help debug it?"&lt;br&gt;
Details matter. The more the model knows, the better it performs.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;🧩 4. &lt;strong&gt;Break It Into Steps&lt;/strong&gt;&lt;br&gt;
Avoid asking everything in one go. Go modular.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;❌ "Build me a chatbot with memory and emotion."&lt;br&gt;
✅ "Step 1: Help me create a basic chatbot in Node.js. Step 2: How can I add memory support?"&lt;br&gt;
Think of it as a conversation, not a monologue.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;🔁 5. &lt;strong&gt;Use Examples&lt;/strong&gt;&lt;br&gt;
Give inputs and desired outputs.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Input: "I like apples and bananas"&lt;br&gt;
Expected Output: ["apples", "bananas"]&lt;br&gt;
It makes your expectation crystal clear.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;❓ 6. &lt;strong&gt;Ask for Clarifications (Yes, Really)&lt;/strong&gt;&lt;br&gt;
Ask the model to review your prompt before answering.&lt;br&gt;
"Before you answer, tell me if any part of this prompt is unclear or could be improved."&lt;br&gt;
This practice helps catch weak spots early.&lt;/p&gt;

&lt;h2&gt;
  
  
  What If You're Not Getting the Results You Want?
&lt;/h2&gt;

&lt;p&gt;That's part of the process. Prompt engineering is iterative - like coding.&lt;br&gt;
Here's what to do:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Read your prompt again. Is it vague or missing info?&lt;/li&gt;
&lt;li&gt;Read the response and ask: "What did it miss?"&lt;/li&gt;
&lt;li&gt;Tweak one thing at a time and retry.&lt;/li&gt;
&lt;li&gt;You can even ask the model:
"Why might this answer not be what I expected?"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Over time, you'll build a sense for what works and what doesn't.&lt;/p&gt;

&lt;p&gt;Learning References: &lt;br&gt;
&lt;a href="https://platform.openai.com/docs/guides/prompt-engineering" rel="noopener noreferrer"&gt;OpenAI Prompt Engineering Guide&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="//www.promptingguide.ai"&gt;Prompt Engineering Guide&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>promptengineering</category>
      <category>chatgpt</category>
      <category>claudeai</category>
    </item>
    <item>
      <title>Codeium is not Codeium anymore—It's Windsurf 🌊</title>
      <dc:creator>Shreyas Hupare</dc:creator>
      <pubDate>Sun, 13 Apr 2025 17:36:20 +0000</pubDate>
      <link>https://dev.to/medianova/codeium-is-not-codeium-anymore-its-windsurf-21gb</link>
      <guid>https://dev.to/medianova/codeium-is-not-codeium-anymore-its-windsurf-21gb</guid>
      <description>&lt;p&gt;&lt;strong&gt;Faster &amp;amp; Better coding than the Codeium extension? Meet the Windsurf Editor&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Hey folks! If you've been using Codeium as your go-to AI coding buddy, it's time to update your bookmarks (and maybe your brain). Because Codeium just got a whole new name and identity:&lt;br&gt;
Codeium is now Windsurf.&lt;br&gt;
 Same vision, same team - just with more flow. Literally.&lt;br&gt;
But this isn't just a name change. It's a whole evolution. And today, we're diving deep into what's new, what's better, and why you should care - especially if you're a developer looking to level up your productivity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why the name change to Windsurf?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's be honest, Codeium was a bit of a spelling nightmare for many, and the name started to feel more about just "code" than the complete dev experience. Windsurf captures the feeling of gliding through your dev work with the wind at your back - no friction, just flow.&lt;br&gt;
So… &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is the Windsurf Editor?&lt;/strong&gt;&lt;br&gt;
The Windsurf Editor is a full-fledged AI-powered IDE - not just an extension like before.&lt;br&gt;
Think of it like this:&lt;br&gt;
The Codeium extension lived inside your VS Code or JetBrains IDE.&lt;br&gt;
The Windsurf Editor is the IDE. A standalone platform tailored from scratch to give you a tighter, faster, and more AI-native dev experience.&lt;/p&gt;

&lt;p&gt;And yes, it's lightning fast. 🧠⚡&lt;br&gt;
 &lt;br&gt;
&lt;strong&gt;What happened to the old extensions?&lt;/strong&gt;&lt;br&gt;
Don't worry! The existing extensions aren't going anywhere - they've just been renamed:&lt;br&gt;
Windsurf Plugins = Formerly Codeium extensions.&lt;br&gt;
You can still use them in VS Code or JetBrains, but honestly, after trying the Windsurf Editor, you might not want to go back. Here's why…&lt;br&gt;
Windsurf Editor vs Windsurf Plugin (Extension)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcu949aqwup8dfzpghkfi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcu949aqwup8dfzpghkfi.png" alt="Image description" width="800" height="459"&gt;&lt;/a&gt;&lt;br&gt;
Let's talk about Cascade: Your new AI collaborator&lt;br&gt;
In Windsurf Editor, chat isn't just chat anymore. It's called Cascade. Think of it like an AI teammate that understands your code and your intention.&lt;br&gt;
You choose a mode - either:&lt;br&gt;
✍️ Write - AI will directly make code changes in your file.&lt;br&gt;
💬 Chat - More exploratory, you can ask questions and get context-aware help.&lt;br&gt;
Cascade understands your workspace, your files, and even what's open in your editor. So suggestions are a lot more accurate and impactful than a generic LLM in a browser.&lt;br&gt;
Smarter, Context-Aware Suggestions&lt;br&gt;
Real-time Preview Before You Accept Changes&lt;/p&gt;

&lt;p&gt;Let's say you're working on an HTML/CSS file and ask Cascade to tweak something. Before you hit "Apply," the Windsurf Editor shows you a live preview of the webpage, so you know exactly what you're getting.&lt;br&gt;
No more guesswork. No more "Oh crap, that broke everything."&lt;br&gt;
What about existing VS Code users?&lt;br&gt;
Good news: Windsurf Editor can import your VS Code settings and extensions. So switching over doesn't feel like starting from scratch.&lt;br&gt;
You still get:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The familiar layout&lt;/li&gt;
&lt;li&gt;Your favorite themes&lt;/li&gt;
&lt;li&gt;Your keyboard shortcuts
But now with a smarter brain and tighter workflow.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;So, should you switch?&lt;/strong&gt;&lt;br&gt;
If you're using Codeium (Windsurf Plugin) inside VS Code and you're happy with it, that's great.&lt;br&gt;
But if you're ready to:&lt;br&gt;
Work faster with deeper AI integration&lt;br&gt;
Get more accurate, context-rich suggestions&lt;br&gt;
Preview changes before applying them&lt;br&gt;
Have a single editor that just flows&lt;/p&gt;

&lt;p&gt;Then &lt;strong&gt;yes&lt;/strong&gt; - Windsurf Editor is definitely worth the try.&lt;br&gt;
Windsurf's MCP (Model Context Protocol)&lt;/p&gt;

&lt;p&gt;What if your AI assistant could not only understand your code…&lt;br&gt;
 …but also your external data like PR comments from GitHub, your Slack threads, your Jira tickets, and even your Notion docs?&lt;br&gt;
That's exactly what MCP is built for.&lt;br&gt;
What does MCP do?&lt;br&gt;
MCP allows the Windsurf Editor and Cascade to pull in relevant context from external platforms, giving it a much deeper understanding of what you're trying to do.&lt;br&gt;
Currently, the number of tools that a user can have access to from the MCP servers at one time is limited to 50.&lt;br&gt;
How to Setup ? &lt;/p&gt;

&lt;p&gt;Already loving Codeium? Read my previous blog&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="https://shreyashupare.medium.com/codeium-visual-studio-code-plugin-6869ab3bced7" class="ltag__link__link" rel="noopener noreferrer"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fv2%2Fda%3Atrue%2Fresize%3Afill%3A88%3A88%2F0%2AG2QJlKWp7XUBgu5j" alt="Shreyas Hupare"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://shreyashupare.medium.com/codeium-visual-studio-code-plugin-6869ab3bced7" class="ltag__link__link" rel="noopener noreferrer"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Codeium :Visual Studio code Plugin | by Shreyas Hupare | Medium&lt;/h2&gt;
      &lt;h3&gt;Shreyas Hupare ・ &lt;time&gt;Oct 13, 2024&lt;/time&gt; ・ 
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.dev.to%2Fassets%2Fmedium-f709f79cf29704f9f4c2a83f950b2964e95007a3e311b77f686915c71574fef2.svg" alt="Medium Logo"&gt;
        shreyashupare.Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;Give it a try..&lt;/p&gt;

</description>
      <category>ai</category>
      <category>aitools</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>The Ultimate Guide to Dependency Injection in NestJS</title>
      <dc:creator>Shreyas Hupare</dc:creator>
      <pubDate>Thu, 10 Apr 2025 09:00:29 +0000</pubDate>
      <link>https://dev.to/medianova/the-ultimate-guide-to-dependency-injection-in-nestjs-3l22</link>
      <guid>https://dev.to/medianova/the-ultimate-guide-to-dependency-injection-in-nestjs-3l22</guid>
      <description>&lt;p&gt;&lt;strong&gt;Why do we use dependency injection?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you’re developing a smaller component of your system, such as a module or a class, you often require functionality from other classes. For instance, you might need an HTTP service for making backend calls. Dependency Injection (DI) is a design pattern and mechanism that facilitates the creation and provision of certain application parts to other parts of the application that need them. DI allows you to decouple components and manage their dependencies more efficiently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why do we have separate modules?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Feature Module:&lt;br&gt;
A feature module serves to organize code relevant to a specific feature, aiding in code organization and establishing clear boundaries. This practice helps manage complexity and encourages adherence to SOLID principles.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Shared Module:&lt;br&gt;
A shared module is a modular component housing features, functionalities, or services intended for use across different parts of the application. It facilitates the organization and encapsulation of code that may be reused throughout the application, such as utility functions, common services, or custom decorators.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Global Module:&lt;br&gt;
A global module is a specialized module providing services or functionality intended to be available throughout the entire application. These modules typically offer application-wide services like logging, configuration, database connections, or authentication services.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To denote a global module in NestJS, the &lt;code&gt;@Global()&lt;/code&gt; decorator from the @nestjs/common package is employed. Decorating a module class with &lt;code&gt;@Global()&lt;/code&gt; signifies to NestJS that the module and its provided services should be globally accessible throughout the application, eliminating the need for explicit imports in the modules where they are utilized.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Providers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Providers in NestJS serve as services or dependencies that can be injected into other components such as controllers, other services, or custom decorators.&lt;br&gt;
NestJS initializes providers and resolves their dependencies during the startup phase of your application. This process occurs when your application begins running.&lt;br&gt;
  When you import modules containing providers, NestJS instantiates these providers and stores them in its built-in Dependency Injection (DI) container. Before creating a new instance, the DI container checks if an instance of the service already exists. Throughout the application’s lifecycle, the DI container maintains a registry of all providers and their instances. It manages the lifecycle of these instances, including their creation, resolution, and disposal.&lt;br&gt;
In scenarios of nested service calls, where a service method is invoked within another service method, NestJS consistently utilizes the same instance of the service. This approach ensures that any modifications to the service’s state within the nested call hierarchy are consistently reflected throughout the application.&lt;br&gt;
The @Injectable() decorator marks a class as a provider in NestJS. By applying @Injectable() to a class, you enable the injection of instances of that class into other components using constructor injection or property injection.&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 { ExampleService } from './example.service';

@Injectable()
export class ExampleController {
  constructor(private readonly exampleService: ExampleService) {}

  // Controller logic...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Scope in NestJS determines the lifecycle and availability of providers. There are three primary scopes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Singleton: This is the default scope where a single instance of a provider is shared across the entire application. Any component that injects this provider will receive the same instance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Transient: In this scope, a new instance of a provider is created each time it is injected. This ensures that each component receives a fresh instance of the provider.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Request: Here, a new instance of a provider is created for each incoming HTTP request. This instance is available only within the scope of that particular request. Once the request is completed, the instance is discarded.&lt;br&gt;
Issue Encountered with Dependency Service in NestJS Application&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The problem arose when utilizing a configuration service responsible for providing config values throughout the application. Various services from different modules relied on this configuration service. Employing Dependency Injection (DI) enabled this service to be injectable with a default scope, typically singleton, meaning the same instance persisted throughout the application’s lifecycle. However, two distinct methods were employed to integrate this service into different modules.&lt;/p&gt;

&lt;p&gt;One approach involved including the configuration service in the import array, as defined in Module C. Conversely, in Module B, the service was added to the providers array. This distinction led to a discrepancy: when updating the configuration service, the services within Module C received the latest configuration, while those within Module B retained outdated configuration values.&lt;/p&gt;

&lt;p&gt;Understand the issue with an example of the code:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;service A&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;import { Injectable} from '@nestjs/common';

@Injectable()
export class UserService {
  private user: string = '';

  getUser() {
    return this.user;
  }

  updateUser() {
    const x = ...  // db operation to get the value of x
    this.user = x;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;module A&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;import { Module } from '@nestjs/common';
import { UserService } from './user.service';
@Module({
  providers: [UserService],
  exports: [UserService], // Export UserService for injection
})
export class UserModule {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;module B&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;import { Module } from '@nestjs/common';
import { UserService } from '../user/user.service';

@Module({
  providers: [UserService],
})
export class ModuleB {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;module C&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;import { Module } from '@nestjs/common';
import { UserModule } from '../user/user.module';

@Module({
  imports: [UserModule],
})
export class ModuleC {}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why was the above scenario occurring?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Every time you add a provider to a providers array, you’re telling Nest to create that provider in the current module’s context. That means a new instance is getting created, and different instances can have different values, which are causing this issue. If you only want one instance (usually the case), you just need to import the module that originally exports the provider.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How it typically works:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Creation of Provider Services: When you define a provider using the @Injectable() decorator, NestJS creates an instance of that provider and registers it within the DI container. This instance will be reused whenever it is requested within the same module context unless you specify otherwise (e.g., if you’re using a provider with the &lt;code&gt;@Scope()&lt;/code&gt; decorator).&lt;br&gt;
Disposal of Provider Services: The disposal of provider services typically happens when the application shuts down. NestJS handles the cleanup of resources automatically, so you generally don’t need to worry about explicitly disposing of services.&lt;br&gt;
Updates on Class Properties: If you have class properties that get updated dynamically, you need to be careful about the scope and lifecycle of your provider instances. Changes to class properties will affect the instance of the class within the scope where it’s instantiated. If a provider is singleton-scoped (which is the default scope in NestJS), changes to its properties will affect all consumers within the same application instance.&lt;br&gt;
Module Context: In NestJS, modules provide a way to organize the application into cohesive blocks of functionality. Each module has its own DI container, which means that providers registered within a module are scoped to that module. Therefore, changes to a provider’s properties will only affect other providers or components within the same module.&lt;br&gt;
The instance created by providing it in the providers array of that module is scoped to the module and is independent of the singleton instance at the application level because they are separate instances with their own memory space. Any updates made to the properties of the service instance will not affect the instance in the context of the module.&lt;br&gt;
&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Using the global decorator, you don’t need to import it everywhere it’s required, as it is available throughout the application.&lt;br&gt;
Import it in the module instead of providing it in the providers array.&lt;br&gt;
&lt;strong&gt;Precautions:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Make sure you’re not redefining the service within the module using the providers array.&lt;br&gt;
Make sure you’re not inadvertently importing or providing the service multiple times within the module or its parent modules.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/@shreyashupare/nestjs-dependency-injection-c7262963560f" rel="noopener noreferrer"&gt;Medium&lt;/a&gt;&lt;/p&gt;

</description>
      <category>nestjs</category>
      <category>dependencyinjection</category>
      <category>programming</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Error handling in NestJS</title>
      <dc:creator>Shreyas Hupare</dc:creator>
      <pubDate>Fri, 04 Apr 2025 18:33:00 +0000</pubDate>
      <link>https://dev.to/medianova/error-handling-in-nestjs-4606</link>
      <guid>https://dev.to/medianova/error-handling-in-nestjs-4606</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is Error Handling?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Error handling is the process of managing and responding to errors that occur during the execution of a program. It involves detecting, handling, and recovering from errors gracefully to ensure the stability and reliability of the application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How Does NestJS Handle Exceptions?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When an exception is thrown in JavaScript, whether inside an asynchronous function or synchronous code, it interrupts the normal flow of execution. The JavaScript runtime immediately stops executing the current function and begins to unwind the call stack, looking for a suitable exception handler to handle the error. This is called “exception unwinding”.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here’s how it works:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Exception Thrown: When an exception occurs, JavaScript immediately stops executing the current code block and starts to unwind the call stack.&lt;br&gt;
Call Stack Unwinding: The JavaScript runtime begins to pop functions off the call stack, returning control to the functions that invoked them. This process continues until the exception is caught by a suitable exception handler or until it reaches the global scope.&lt;br&gt;
Exception Handling: If there’s a try-catch block surrounding the code that threw the exception, JavaScript jumps to the appropriate catch block. If there’s no catch block in the current function, JavaScript continues unwinding the call stack, searching for a catch block in the calling function, and so on.&lt;br&gt;
Global Exception Filter: If the exception isn’t caught in try-catch anywhere, then the exception filter intercepts and handles it gracefully. However, this doesn’t always work in the case of errors thrown in asynchronous functions.&lt;br&gt;
Unhandled Exception: If the exception isn’t caught anywhere above, it becomes an “unhandled rejection”.&lt;br&gt;
What Happens When an Exception is Thrown within an Asynchronous Function?&lt;/p&gt;

&lt;p&gt;In NestJS, the global exception filter plays a crucial role in catching and handling errors that occur within the application. NestJS’s global exception filters operate synchronously, intercepting errors as they propagate up the call stack. However, when it comes to errors thrown in asynchronous functions, the global exception filter might not always catch them as expected.&lt;/p&gt;

&lt;p&gt;This behaviour occurs because async functions in JavaScript return a Promise. When an error is thrown within an async function, it is encapsulated within that Promise. As a result, the error is not immediately thrown in the calling context but rather captured within the Promise’s rejection handler and the error thrown is queued within the event loop, i.e., it’s deferred until the Promise is either awaited or handled. This means that by the time the error propagates back to the global exception filter, it might have already passed the point where the filter could intercept it.&lt;/p&gt;

&lt;p&gt;To address this issue, you can manually catch errors within the async functions and handle them appropriately.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;You can find more information about exception filters in NestJS’s documentation — &lt;a href="https://docs.nestjs.com/exception-filters" rel="noopener noreferrer"&gt;Exception Filters&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>nestjs</category>
      <category>errors</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
