{"id":4931,"date":"2026-02-18T05:47:41","date_gmt":"2026-02-18T05:47:41","guid":{"rendered":"https:\/\/softcolontechnologies.com\/blogs\/?p=4931"},"modified":"2026-02-18T05:48:42","modified_gmt":"2026-02-18T05:48:42","slug":"how-to-build-production-grade-applications-with-nestjs","status":"publish","type":"post","link":"https:\/\/www.softcolon.com\/blogs\/how-to-build-production-grade-applications-with-nestjs\/","title":{"rendered":"How to Build Production-Grade Applications with NestJS"},"content":{"rendered":"<h2 class=\"text-3xl font-semibold mt-14 mb-8 \">Introduction: When Simple Express Scripts Aren&#8217;t Enough<\/h2>\n<p class=\" text-lg my-6\">You start with a simple Node.js project. A few Express routes, some database calls, maybe authentication. The code works, and you ship it.<\/p>\n<p class=\" text-lg my-6\">Then your project grows.<\/p>\n<p class=\" text-lg my-6\">Six months later:<\/p>\n<ul class=\"list-disc ml-6 my-6\">\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">You have 50 route handlers scattered across 10 files<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Business logic is mixed everywhere (controllers, middleware, utility functions)<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Adding a new feature requires changes in 5 different places<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Tests are fragile because everything depends on everything else<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">New developers take 2 weeks to understand the codebase<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">A simple change breaks something unexpected<\/p>\n<\/li>\n<\/ul>\n<p class=\" text-lg my-6\"><strong>This is where NestJS comes in.<\/strong><\/p>\n<p class=\" text-lg my-6\">NestJS is a <strong>progressive backend framework<\/strong> for Node.js that brings <strong>enterprise-grade architecture to JavaScript development<\/strong>. It&#8217;s built on top of Express (or Fastify), but adds structure, patterns, and tools that make large applications manageable.<\/p>\n<p class=\" text-lg my-6\">Think of it like the difference between:<\/p>\n<ul class=\"list-disc ml-6 my-6\">\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>Express:<\/strong> Flexible toolkit (you decide the architecture)<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>NestJS:<\/strong> Complete framework (proven architecture, best practices built-in)<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h2 class=\"text-3xl font-semibold mt-14 mb-8 \">The Evolution of Node.js Backend Development<\/h2>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">Stage 1: Simple Scripts (Express)<\/h3>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-javascript whitespace-pre-wrap break-words text-gray-300\"><span class=\"hljs-comment\">\/\/ routes.js - Everything mixed together<\/span>\napp.<span class=\"hljs-title function_\">get<\/span>(<span class=\"hljs-string\">'\/users\/:id'<\/span>, <span class=\"hljs-function\">(<span class=\"hljs-params\">req, res<\/span>) =&gt;<\/span> {\n    <span class=\"hljs-keyword\">const<\/span> userId = req.<span class=\"hljs-property\">params<\/span>.<span class=\"hljs-property\">id<\/span>;\n    <span class=\"hljs-comment\">\/\/ Business logic mixed with HTTP handling<\/span>\n    <span class=\"hljs-keyword\">const<\/span> user = database.<span class=\"hljs-title function_\">query<\/span>(<span class=\"hljs-string\">`SELECT * FROM users WHERE id = <span class=\"hljs-subst\">${userId}<\/span>`<\/span>);\n    res.<span class=\"hljs-title function_\">json<\/span>(user);\n});\n\napp.<span class=\"hljs-title function_\">post<\/span>(<span class=\"hljs-string\">'\/users'<\/span>, <span class=\"hljs-function\">(<span class=\"hljs-params\">req, res<\/span>) =&gt;<\/span> {\n    <span class=\"hljs-comment\">\/\/ Validation mixed in<\/span>\n    <span class=\"hljs-keyword\">if<\/span> (!req.<span class=\"hljs-property\">body<\/span>.<span class=\"hljs-property\">email<\/span>) {\n        <span class=\"hljs-keyword\">return<\/span> res.<span class=\"hljs-title function_\">status<\/span>(<span class=\"hljs-number\">400<\/span>).<span class=\"hljs-title function_\">json<\/span>({ <span class=\"hljs-attr\">error<\/span>: <span class=\"hljs-string\">'Email required'<\/span> });\n    }\n    <span class=\"hljs-comment\">\/\/ More business logic<\/span>\n    <span class=\"hljs-keyword\">const<\/span> user = database.<span class=\"hljs-title function_\">create<\/span>(req.<span class=\"hljs-property\">body<\/span>);\n    res.<span class=\"hljs-title function_\">json<\/span>(user);\n});\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<p class=\" text-lg my-6\"><strong>Problems:<\/strong><\/p>\n<ul class=\"list-disc ml-6 my-6\">\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">\u274c Business logic mixed with HTTP concerns<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">\u274c Hard to test (everything depends on Express\/HTTP)<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">\u274c Duplicated validation and error handling<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">\u274c Unclear code structure for new developers<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">\u274c Difficult to reuse logic across endpoints<\/p>\n<\/li>\n<\/ul>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">Stage 2: Better Organized Express<\/h3>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-javascript whitespace-pre-wrap break-words text-gray-300\"><span class=\"hljs-comment\">\/\/ userController.js<\/span>\n<span class=\"hljs-built_in\">exports<\/span>.<span class=\"hljs-property\">getUser<\/span> = <span class=\"hljs-function\">(<span class=\"hljs-params\">req, res<\/span>) =&gt;<\/span> {\n    <span class=\"hljs-keyword\">const<\/span> user = userService.<span class=\"hljs-title function_\">findById<\/span>(req.<span class=\"hljs-property\">params<\/span>.<span class=\"hljs-property\">id<\/span>);\n    res.<span class=\"hljs-title function_\">json<\/span>(user);\n};\n\n<span class=\"hljs-comment\">\/\/ userService.js<\/span>\n<span class=\"hljs-built_in\">exports<\/span>.<span class=\"hljs-property\">findById<\/span> = <span class=\"hljs-function\">(<span class=\"hljs-params\">id<\/span>) =&gt;<\/span> {\n    <span class=\"hljs-keyword\">return<\/span> database.<span class=\"hljs-title function_\">query<\/span>(<span class=\"hljs-string\">`SELECT * FROM users WHERE id = <span class=\"hljs-subst\">${id}<\/span>`<\/span>);\n};\n\n<span class=\"hljs-comment\">\/\/ routes.js<\/span>\napp.<span class=\"hljs-title function_\">get<\/span>(<span class=\"hljs-string\">'\/users\/:id'<\/span>, userController.<span class=\"hljs-property\">getUser<\/span>);\napp.<span class=\"hljs-title function_\">post<\/span>(<span class=\"hljs-string\">'\/users'<\/span>, userController.<span class=\"hljs-property\">createUser<\/span>);\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<p class=\" text-lg my-6\"><strong>Better, but still problems:<\/strong><\/p>\n<ul class=\"list-disc ml-6 my-6\">\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">\u274c No built-in way to manage dependencies<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">\u274c Manual error handling everywhere<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">\u274c Testing requires mocking HTTP layer<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">\u274c Inconsistent patterns across the team<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">\u274c No built-in validation or serialization<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">\u274c Hard to add cross-cutting concerns (logging, auth)<\/p>\n<\/li>\n<\/ul>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">Stage 3: NestJS (Production-Ready)<\/h3>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-typescript whitespace-pre-wrap break-words text-gray-300\"><span class=\"hljs-comment\">\/\/ user.service.ts<\/span>\n<span class=\"hljs-meta\">@Injectable<\/span>()\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">UserService<\/span> {\n    <span class=\"hljs-title function_\">constructor<\/span>(<span class=\"hljs-params\"><span class=\"hljs-keyword\">private<\/span> <span class=\"hljs-attr\">db<\/span>: <span class=\"hljs-title class_\">Database<\/span><\/span>) {}\n    \n    <span class=\"hljs-title function_\">findById<\/span>(<span class=\"hljs-params\"><span class=\"hljs-attr\">id<\/span>: <span class=\"hljs-built_in\">string<\/span><\/span>) {\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">db<\/span>.<span class=\"hljs-property\">user<\/span>.<span class=\"hljs-title function_\">findUnique<\/span>({ <span class=\"hljs-attr\">where<\/span>: { id } });\n    }\n}\n\n<span class=\"hljs-comment\">\/\/ user.controller.ts<\/span>\n<span class=\"hljs-meta\">@Controller<\/span>(<span class=\"hljs-string\">'users'<\/span>)\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">UserController<\/span> {\n    <span class=\"hljs-title function_\">constructor<\/span>(<span class=\"hljs-params\"><span class=\"hljs-keyword\">private<\/span> <span class=\"hljs-attr\">userService<\/span>: <span class=\"hljs-title class_\">UserService<\/span><\/span>) {}\n    \n    <span class=\"hljs-meta\">@Get<\/span>(<span class=\"hljs-string\">':id'<\/span>)\n    <span class=\"hljs-title function_\">getUser<\/span>(<span class=\"hljs-params\"><span class=\"hljs-meta\">@Param<\/span>(<span class=\"hljs-string\">'id'<\/span>) <span class=\"hljs-attr\">id<\/span>: <span class=\"hljs-built_in\">string<\/span><\/span>) {\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">userService<\/span>.<span class=\"hljs-title function_\">findById<\/span>(id);\n    }\n}\n\n<span class=\"hljs-comment\">\/\/ user.module.ts<\/span>\n<span class=\"hljs-meta\">@Module<\/span>({\n    <span class=\"hljs-attr\">controllers<\/span>: [<span class=\"hljs-title class_\">UserController<\/span>],\n    <span class=\"hljs-attr\">providers<\/span>: [<span class=\"hljs-title class_\">UserService<\/span>],\n})\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">UserModule<\/span> {}\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<p class=\" text-lg my-6\"><strong>Benefits:<\/strong><\/p>\n<ul class=\"list-disc ml-6 my-6\">\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">\u2705 Clear separation of concerns<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">\u2705 Dependency injection (services are injected automatically)<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">\u2705 Easy to test (just pass mock services)<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">\u2705 Consistent patterns across the team<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">\u2705 Built-in validation, error handling, logging<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">\u2705 Scalable to thousands of lines of code<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h2 class=\"text-3xl font-semibold mt-14 mb-8 \">Why NestJS? The Problems It Solves<\/h2>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">Problem 1: Unstructured Code<\/h3>\n<p class=\" text-lg my-6\">As Express apps grow, there&#8217;s no standard structure. Different developers organize code differently, making onboarding and maintenance painful.<\/p>\n<p class=\" text-lg my-6\"><strong>NestJS Solution:<\/strong> Enforces a proven structure with modules, controllers, and services.<\/p>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-json whitespace-pre-wrap break-words text-gray-300\">my-app\/\n\u251c\u2500\u2500 src\/\n\u2502   \u251c\u2500\u2500 users\/\n\u2502   \u2502   \u251c\u2500\u2500 user.controller.ts\n\u2502   \u2502   \u251c\u2500\u2500 user.service.ts\n\u2502   \u2502   \u251c\u2500\u2500 user.entity.ts\n\u2502   \u2502   \u251c\u2500\u2500 dto\/\n\u2502   \u2502   \u2502   \u251c\u2500\u2500 create-user.dto.ts\n\u2502   \u2502   \u2502   \u2514\u2500\u2500 update-user.dto.ts\n\u2502   \u2502   \u2514\u2500\u2500 user.module.ts\n\u2502   \u251c\u2500\u2500 posts\/\n\u2502   \u2502   \u251c\u2500\u2500 post.controller.ts\n\u2502   \u2502   \u251c\u2500\u2500 post.service.ts\n\u2502   \u2502   \u251c\u2500\u2500 post.entity.ts\n\u2502   \u2502   \u2514\u2500\u2500 post.module.ts\n\u2502   \u2514\u2500\u2500 app.module.ts\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<p class=\" text-lg my-6\">Every developer knows where to look. New features follow the same pattern.<\/p>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">Problem 2: Hard-to-Scale Architecture<\/h3>\n<p class=\" text-lg my-6\">In a poorly structured Express app, adding features becomes harder as the codebase grows. There&#8217;s no clear way to organize different parts of the application.<\/p>\n<p class=\" text-lg my-6\"><strong>NestJS Solution:<\/strong> Modular architecture where features are isolated in modules that can be developed, tested, and deployed independently.<\/p>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-json whitespace-pre-wrap break-words text-gray-300\">Instead of<span class=\"hljs-punctuation\">:<\/span>\napp.js (<span class=\"hljs-number\">500<\/span> lines of everything)\n\nYou get<span class=\"hljs-punctuation\">:<\/span>\nauth.module.ts (Auth feature)\nusers.module.ts (User feature)\nposts.module.ts (Post feature)\nanalytics.module.ts (Analytics feature)\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<p class=\" text-lg my-6\">Each module is self-contained and can be maintained independently.<\/p>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">Problem 3: Dependency Management<\/h3>\n<p class=\" text-lg my-6\">Passing dependencies around (services, database connections, etc.) becomes messy in Express.<\/p>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-javascript whitespace-pre-wrap break-words text-gray-300\"><span class=\"hljs-comment\">\/\/ \u274c Manual dependency passing<\/span>\n<span class=\"hljs-keyword\">const<\/span> db = <span class=\"hljs-built_in\">require<\/span>(<span class=\"hljs-string\">'.\/database'<\/span>);\n<span class=\"hljs-keyword\">const<\/span> cache = <span class=\"hljs-built_in\">require<\/span>(<span class=\"hljs-string\">'.\/cache'<\/span>);\n<span class=\"hljs-keyword\">const<\/span> logger = <span class=\"hljs-built_in\">require<\/span>(<span class=\"hljs-string\">'.\/logger'<\/span>);\n\n<span class=\"hljs-keyword\">const<\/span> userService = <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">UserService<\/span>(db, cache, logger);\n<span class=\"hljs-keyword\">const<\/span> userController = <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">UserController<\/span>(userService);\n<span class=\"hljs-keyword\">const<\/span> postService = <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">PostService<\/span>(db, cache, logger);\n<span class=\"hljs-keyword\">const<\/span> postController = <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">PostController<\/span>(postService);\n\n<span class=\"hljs-comment\">\/\/ This gets out of hand quickly!<\/span>\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<p class=\" text-lg my-6\"><strong>NestJS Solution:<\/strong> Automatic dependency injection. You declare what you need, and NestJS provides it.<\/p>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-typescript whitespace-pre-wrap break-words text-gray-300\"><span class=\"hljs-comment\">\/\/ \u2705 Dependencies are injected automatically<\/span>\n<span class=\"hljs-meta\">@Injectable<\/span>()\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">UserService<\/span> {\n    <span class=\"hljs-title function_\">constructor<\/span>(<span class=\"hljs-params\">\n        <span class=\"hljs-keyword\">private<\/span> <span class=\"hljs-attr\">db<\/span>: <span class=\"hljs-title class_\">Database<\/span>,\n        <span class=\"hljs-keyword\">private<\/span> <span class=\"hljs-attr\">cache<\/span>: <span class=\"hljs-title class_\">CacheService<\/span>,\n        <span class=\"hljs-keyword\">private<\/span> <span class=\"hljs-attr\">logger<\/span>: <span class=\"hljs-title class_\">LoggerService<\/span>\n    <\/span>) {}\n}\n\n<span class=\"hljs-comment\">\/\/ NestJS handles instantiation and injection<\/span>\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">Problem 4: Inconsistent Patterns<\/h3>\n<p class=\" text-lg my-6\">Different developers handle authentication, error handling, validation, and logging differently, leading to bugs and confusion.<\/p>\n<p class=\" text-lg my-6\"><strong>NestJS Solution:<\/strong> Enforces consistent patterns through Guards, Pipes, and Interceptors.<\/p>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-typescript whitespace-pre-wrap break-words text-gray-300\"><span class=\"hljs-comment\">\/\/ \u2705 Consistent authentication<\/span>\n<span class=\"hljs-meta\">@Controller<\/span>(<span class=\"hljs-string\">'users'<\/span>)\n<span class=\"hljs-meta\">@UseGuards<\/span>(<span class=\"hljs-title class_\">JwtAuthGuard<\/span>)\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">UserController<\/span> {\n    <span class=\"hljs-meta\">@Get<\/span>()\n    <span class=\"hljs-title function_\">getUsers<\/span>() { ... }\n}\n\n<span class=\"hljs-comment\">\/\/ \u2705 Consistent validation<\/span>\n<span class=\"hljs-meta\">@Post<\/span>()\n<span class=\"hljs-title function_\">createUser<\/span>(<span class=\"hljs-params\"><span class=\"hljs-meta\">@Body<\/span>(<span class=\"hljs-keyword\">new<\/span> ValidationPipe()) <span class=\"hljs-attr\">createUserDto<\/span>: <span class=\"hljs-title class_\">CreateUserDto<\/span><\/span>) { ... }\n\n<span class=\"hljs-comment\">\/\/ \u2705 Consistent error handling<\/span>\n<span class=\"hljs-comment\">\/\/ Done via exception filters that all errors pass through<\/span>\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<hr \/>\n<h2 class=\"text-3xl font-semibold mt-14 mb-8 \">What NestJS Gives You<\/h2>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">1. Opinionated Structure<\/h3>\n<p class=\" text-lg my-6\">NestJS has a well-defined way to organize code. Everyone on the team follows the same patterns, making code reviews, onboarding, and maintenance easier.<\/p>\n<p class=\" text-lg my-6\"><strong>Structure:<\/strong><\/p>\n<ul class=\"list-disc ml-6 my-6\">\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>Controllers:<\/strong> Handle HTTP requests\/responses<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>Services:<\/strong> Contain business logic<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>Modules:<\/strong> Group related features<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>Entities:<\/strong> Database models<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>DTOs:<\/strong> Data validation and transformation<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>Guards:<\/strong> Authentication and authorization<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>Interceptors:<\/strong> Cross-cutting concerns (logging, error handling)<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>Pipes:<\/strong> Data validation and transformation<\/p>\n<\/li>\n<\/ul>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">2. Built-in Dependency Injection<\/h3>\n<p class=\" text-lg my-6\">NestJS automatically manages object creation and dependency injection. You declare what you need, and it&#8217;s provided automatically.<\/p>\n<p class=\" text-lg my-6\"><strong>Benefits:<\/strong><\/p>\n<ul class=\"list-disc ml-6 my-6\">\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Cleaner code (no manual instantiation)<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Easier testing (swap real services with mocks)<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Better loose coupling between components<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Easier to add new dependencies<\/p>\n<\/li>\n<\/ul>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">3. TypeScript First<\/h3>\n<p class=\" text-lg my-6\">NestJS is built for TypeScript (not just JavaScript). This means:<\/p>\n<table>\n<thead>\n<tr>\n<th>Feature<\/th>\n<th>Benefit<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Type safety<\/td>\n<td>Catch errors at compile time, not runtime<\/td>\n<\/tr>\n<tr>\n<td>IDE support<\/td>\n<td>Auto-complete, refactoring, finding usages<\/td>\n<\/tr>\n<tr>\n<td>Self-documenting code<\/td>\n<td>Types serve as inline documentation<\/td>\n<\/tr>\n<tr>\n<td>Better testing<\/td>\n<td>Mocking is type-safe<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">4. Modular Architecture<\/h3>\n<p class=\" text-lg my-6\">Applications are divided into <strong>modules<\/strong>, each responsible for a specific feature.<\/p>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-typescript whitespace-pre-wrap break-words text-gray-300\"><span class=\"hljs-meta\">@Module<\/span>({\n    <span class=\"hljs-attr\">controllers<\/span>: [<span class=\"hljs-title class_\">UserController<\/span>],\n    <span class=\"hljs-attr\">providers<\/span>: [<span class=\"hljs-title class_\">UserService<\/span>],\n    <span class=\"hljs-attr\">exports<\/span>: [<span class=\"hljs-title class_\">UserService<\/span>], <span class=\"hljs-comment\">\/\/ Other modules can use this<\/span>\n})\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">UserModule<\/span> {}\n\n<span class=\"hljs-meta\">@Module<\/span>({\n    <span class=\"hljs-attr\">imports<\/span>: [<span class=\"hljs-title class_\">UserModule<\/span>],  <span class=\"hljs-comment\">\/\/ Import and use UserService<\/span>\n    <span class=\"hljs-attr\">controllers<\/span>: [<span class=\"hljs-title class_\">PostController<\/span>],\n    <span class=\"hljs-attr\">providers<\/span>: [<span class=\"hljs-title class_\">PostService<\/span>],\n})\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">PostModule<\/span> {}\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<p class=\" text-lg my-6\">Benefits:<\/p>\n<ul class=\"list-disc ml-6 my-6\">\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Easy to understand (each module is a feature)<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Easy to test (modules can be tested independently)<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Easy to scale (add modules without affecting others)<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Easy to maintain (changes in one module don&#8217;t break others)<\/p>\n<\/li>\n<\/ul>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">5. First-Class Support for Common Patterns<\/h3>\n<p class=\" text-lg my-6\">NestJS provides built-in solutions for things that are painful in Express:<\/p>\n<table>\n<thead>\n<tr>\n<th>Feature<\/th>\n<th>What It Is<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>Authentication<\/strong><\/td>\n<td>Guards and strategies for JWT, OAuth, etc.<\/td>\n<\/tr>\n<tr>\n<td><strong>Validation<\/strong><\/td>\n<td>Pipes that validate DTOs automatically<\/td>\n<\/tr>\n<tr>\n<td><strong>Error Handling<\/strong><\/td>\n<td>Exception filters that handle all errors consistently<\/td>\n<\/tr>\n<tr>\n<td><strong>Logging<\/strong><\/td>\n<td>Built-in logger and integration with popular log services<\/td>\n<\/tr>\n<tr>\n<td><strong>Database Integration<\/strong><\/td>\n<td>Seamless integration with TypeORM, Prisma, etc.<\/td>\n<\/tr>\n<tr>\n<td><strong>API Documentation<\/strong><\/td>\n<td>Automatic Swagger\/OpenAPI generation<\/td>\n<\/tr>\n<tr>\n<td><strong>Caching<\/strong><\/td>\n<td>Built-in caching decorators<\/td>\n<\/tr>\n<tr>\n<td><strong>WebSockets<\/strong><\/td>\n<td>First-class support for real-time features<\/td>\n<\/tr>\n<tr>\n<td><strong>Microservices<\/strong><\/td>\n<td>Pattern for building distributed systems<\/td>\n<\/tr>\n<tr>\n<td><strong>Testing<\/strong><\/td>\n<td>Test utilities and patterns built-in<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">6. Built for Teams<\/h3>\n<p class=\" text-lg my-6\">The structure and patterns make onboarding new developers much easier.<\/p>\n<p class=\" text-lg my-6\"><strong>Developer onboarding timeline:<\/strong><\/p>\n<ul class=\"list-disc ml-6 my-6\">\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>Express:<\/strong> 2-3 weeks to understand the codebase architecture<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>NestJS:<\/strong> 2-3 days (everyone follows the same patterns)<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h2 class=\"text-3xl font-semibold mt-14 mb-8 \">Core Architecture Concepts<\/h2>\n<p class=\" text-lg my-6\">Before we build something, let&#8217;s understand how NestJS applications work.<\/p>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">Modules: Organizing Features<\/h3>\n<p class=\" text-lg my-6\">Think of modules as <strong>containers for related features<\/strong>. Each module is self-contained.<\/p>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-typescript whitespace-pre-wrap break-words text-gray-300\"><span class=\"hljs-comment\">\/\/ user.module.ts<\/span>\n<span class=\"hljs-meta\">@Module<\/span>({\n    <span class=\"hljs-attr\">controllers<\/span>: [<span class=\"hljs-title class_\">UserController<\/span>],      <span class=\"hljs-comment\">\/\/ HTTP routes<\/span>\n    <span class=\"hljs-attr\">providers<\/span>: [<span class=\"hljs-title class_\">UserService<\/span>],            <span class=\"hljs-comment\">\/\/ Business logic<\/span>\n    <span class=\"hljs-attr\">exports<\/span>: [<span class=\"hljs-title class_\">UserService<\/span>],              <span class=\"hljs-comment\">\/\/ Make available to other modules<\/span>\n})\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">UserModule<\/span> {}\n\n<span class=\"hljs-comment\">\/\/ app.module.ts (Root module)<\/span>\n<span class=\"hljs-meta\">@Module<\/span>({\n    <span class=\"hljs-attr\">imports<\/span>: [<span class=\"hljs-title class_\">UserModule<\/span>, <span class=\"hljs-title class_\">PostModule<\/span>],   <span class=\"hljs-comment\">\/\/ Include other modules<\/span>\n})\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">AppModule<\/span> {}\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<p class=\" text-lg my-6\"><strong>Example structure:<\/strong><\/p>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-json whitespace-pre-wrap break-words text-gray-300\">users\/ (module)\n  \u251c\u2500\u2500 user.controller.ts\n  \u251c\u2500\u2500 user.service.ts\n  \u251c\u2500\u2500 user.entity.ts\n  \u251c\u2500\u2500 dto\/\n  \u2514\u2500\u2500 user.module.ts\n\nposts\/ (module)\n  \u251c\u2500\u2500 post.controller.ts\n  \u251c\u2500\u2500 post.service.ts\n  \u251c\u2500\u2500 post.entity.ts\n  \u2514\u2500\u2500 post.module.ts\n\ncomments\/ (module)\n  \u251c\u2500\u2500 comment.controller.ts\n  \u251c\u2500\u2500 comment.service.ts\n  \u2514\u2500\u2500 comment.module.ts\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<p class=\" text-lg my-6\">Each module can be worked on independently.<\/p>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">Controllers: Handling HTTP Requests<\/h3>\n<p class=\" text-lg my-6\">Controllers receive HTTP requests and send responses. They shouldn&#8217;t contain business logic.<\/p>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-typescript whitespace-pre-wrap break-words text-gray-300\"><span class=\"hljs-meta\">@Controller<\/span>(<span class=\"hljs-string\">'users'<\/span>)  <span class=\"hljs-comment\">\/\/ Routes: \/users<\/span>\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">UserController<\/span> {\n    <span class=\"hljs-title function_\">constructor<\/span>(<span class=\"hljs-params\"><span class=\"hljs-keyword\">private<\/span> <span class=\"hljs-attr\">userService<\/span>: <span class=\"hljs-title class_\">UserService<\/span><\/span>) {}\n    \n    <span class=\"hljs-meta\">@Get<\/span>()                           <span class=\"hljs-comment\">\/\/ GET \/users<\/span>\n    <span class=\"hljs-title function_\">getAllUsers<\/span>() {\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">userService<\/span>.<span class=\"hljs-title function_\">findAll<\/span>();\n    }\n    \n    <span class=\"hljs-meta\">@Get<\/span>(<span class=\"hljs-string\">':id'<\/span>)                      <span class=\"hljs-comment\">\/\/ GET \/users\/:id<\/span>\n    <span class=\"hljs-title function_\">getUserById<\/span>(<span class=\"hljs-params\"><span class=\"hljs-meta\">@Param<\/span>(<span class=\"hljs-string\">'id'<\/span>) <span class=\"hljs-attr\">id<\/span>: <span class=\"hljs-built_in\">string<\/span><\/span>) {\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">userService<\/span>.<span class=\"hljs-title function_\">findById<\/span>(id);\n    }\n    \n    <span class=\"hljs-meta\">@Post<\/span>()                          <span class=\"hljs-comment\">\/\/ POST \/users<\/span>\n    <span class=\"hljs-title function_\">createUser<\/span>(<span class=\"hljs-params\"><span class=\"hljs-meta\">@Body<\/span>() <span class=\"hljs-attr\">createUserDto<\/span>: <span class=\"hljs-title class_\">CreateUserDto<\/span><\/span>) {\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">userService<\/span>.<span class=\"hljs-title function_\">create<\/span>(createUserDto);\n    }\n    \n    <span class=\"hljs-meta\">@Put<\/span>(<span class=\"hljs-string\">':id'<\/span>)                      <span class=\"hljs-comment\">\/\/ PUT \/users\/:id<\/span>\n    <span class=\"hljs-title function_\">updateUser<\/span>(<span class=\"hljs-params\">\n        <span class=\"hljs-meta\">@Param<\/span>(<span class=\"hljs-string\">'id'<\/span>) <span class=\"hljs-attr\">id<\/span>: <span class=\"hljs-built_in\">string<\/span>,\n        <span class=\"hljs-meta\">@Body<\/span>() <span class=\"hljs-attr\">updateUserDto<\/span>: <span class=\"hljs-title class_\">UpdateUserDto<\/span>\n    <\/span>) {\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">userService<\/span>.<span class=\"hljs-title function_\">update<\/span>(id, updateUserDto);\n    }\n    \n    <span class=\"hljs-meta\">@Delete<\/span>(<span class=\"hljs-string\">':id'<\/span>)                   <span class=\"hljs-comment\">\/\/ DELETE \/users\/:id<\/span>\n    <span class=\"hljs-title function_\">deleteUser<\/span>(<span class=\"hljs-params\"><span class=\"hljs-meta\">@Param<\/span>(<span class=\"hljs-string\">'id'<\/span>) <span class=\"hljs-attr\">id<\/span>: <span class=\"hljs-built_in\">string<\/span><\/span>) {\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">userService<\/span>.<span class=\"hljs-title function_\">delete<\/span>(id);\n    }\n}\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<p class=\" text-lg my-6\"><strong>Key points:<\/strong><\/p>\n<ul class=\"list-disc ml-6 my-6\">\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Controllers are thin (just HTTP handling)<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Business logic is in services<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Parameters are extracted declaratively (@Param, @Body, @Query)<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Return values are automatically serialized to JSON<\/p>\n<\/li>\n<\/ul>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">Services: Business Logic<\/h3>\n<p class=\" text-lg my-6\">Services contain the actual business logic. They&#8217;re reusable across different controllers.<\/p>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-typescript whitespace-pre-wrap break-words text-gray-300\"><span class=\"hljs-meta\">@Injectable<\/span>()\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">UserService<\/span> {\n    <span class=\"hljs-title function_\">constructor<\/span>(<span class=\"hljs-params\"><span class=\"hljs-keyword\">private<\/span> <span class=\"hljs-attr\">prisma<\/span>: <span class=\"hljs-title class_\">PrismaService<\/span><\/span>) {}\n    \n    <span class=\"hljs-title function_\">findAll<\/span>() {\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">prisma<\/span>.<span class=\"hljs-property\">user<\/span>.<span class=\"hljs-title function_\">findMany<\/span>();\n    }\n    \n    <span class=\"hljs-title function_\">findById<\/span>(<span class=\"hljs-params\"><span class=\"hljs-attr\">id<\/span>: <span class=\"hljs-built_in\">string<\/span><\/span>) {\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">prisma<\/span>.<span class=\"hljs-property\">user<\/span>.<span class=\"hljs-title function_\">findUnique<\/span>({\n            <span class=\"hljs-attr\">where<\/span>: { id }\n        });\n    }\n    \n    <span class=\"hljs-title function_\">create<\/span>(<span class=\"hljs-params\"><span class=\"hljs-attr\">data<\/span>: <span class=\"hljs-title class_\">CreateUserDto<\/span><\/span>) {\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">prisma<\/span>.<span class=\"hljs-property\">user<\/span>.<span class=\"hljs-title function_\">create<\/span>({ data });\n    }\n    \n    <span class=\"hljs-title function_\">update<\/span>(<span class=\"hljs-params\"><span class=\"hljs-attr\">id<\/span>: <span class=\"hljs-built_in\">string<\/span>, <span class=\"hljs-attr\">data<\/span>: <span class=\"hljs-title class_\">UpdateUserDto<\/span><\/span>) {\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">prisma<\/span>.<span class=\"hljs-property\">user<\/span>.<span class=\"hljs-title function_\">update<\/span>({\n            <span class=\"hljs-attr\">where<\/span>: { id },\n            data\n        });\n    }\n    \n    <span class=\"hljs-title function_\">delete<\/span>(<span class=\"hljs-params\"><span class=\"hljs-attr\">id<\/span>: <span class=\"hljs-built_in\">string<\/span><\/span>) {\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">prisma<\/span>.<span class=\"hljs-property\">user<\/span>.<span class=\"hljs-title function_\">delete<\/span>({\n            <span class=\"hljs-attr\">where<\/span>: { id }\n        });\n    }\n}\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<p class=\" text-lg my-6\"><strong>Key points:<\/strong><\/p>\n<ul class=\"list-disc ml-6 my-6\">\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Services are marked with @Injectable() (they can be injected)<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Services are reusable (multiple controllers can use the same service)<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Services contain no HTTP concerns<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Services are easy to test (just pass a mock database)<\/p>\n<\/li>\n<\/ul>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">Dependency Injection: Automatic Dependency Management<\/h3>\n<p class=\" text-lg my-6\">Instead of manually creating and passing objects, NestJS handles it for you.<\/p>\n<p class=\" text-lg my-6\"><strong>Without Dependency Injection (manual):<\/strong><\/p>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-javascript whitespace-pre-wrap break-words text-gray-300\"><span class=\"hljs-comment\">\/\/ \u274c Manual - hard to manage and test<\/span>\n<span class=\"hljs-keyword\">const<\/span> database = <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">Database<\/span>();\n<span class=\"hljs-keyword\">const<\/span> cache = <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">Cache<\/span>();\n<span class=\"hljs-keyword\">const<\/span> logger = <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">Logger<\/span>();\n<span class=\"hljs-keyword\">const<\/span> userService = <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">UserService<\/span>(database, cache, logger);\n<span class=\"hljs-keyword\">const<\/span> userController = <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">UserController<\/span>(userService);\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<p class=\" text-lg my-6\"><strong>With Dependency Injection (NestJS):<\/strong><\/p>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-typescript whitespace-pre-wrap break-words text-gray-300\"><span class=\"hljs-comment\">\/\/ \u2705 Automatic - NestJS handles it<\/span>\n<span class=\"hljs-meta\">@Injectable<\/span>()\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">UserService<\/span> {\n    <span class=\"hljs-title function_\">constructor<\/span>(<span class=\"hljs-params\">\n        <span class=\"hljs-keyword\">private<\/span> <span class=\"hljs-attr\">db<\/span>: <span class=\"hljs-title class_\">Database<\/span>,\n        <span class=\"hljs-keyword\">private<\/span> <span class=\"hljs-attr\">cache<\/span>: <span class=\"hljs-title class_\">Cache<\/span>,\n        <span class=\"hljs-keyword\">private<\/span> <span class=\"hljs-attr\">logger<\/span>: <span class=\"hljs-title class_\">Logger<\/span>\n    <\/span>) {}\n}\n\n<span class=\"hljs-meta\">@Controller<\/span>(<span class=\"hljs-string\">'users'<\/span>)\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">UserController<\/span> {\n    <span class=\"hljs-title function_\">constructor<\/span>(<span class=\"hljs-params\"><span class=\"hljs-keyword\">private<\/span> <span class=\"hljs-attr\">userService<\/span>: <span class=\"hljs-title class_\">UserService<\/span><\/span>) {}\n}\n\n<span class=\"hljs-comment\">\/\/ NestJS creates instances in the right order and injects them<\/span>\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<p class=\" text-lg my-6\"><strong>Benefits:<\/strong><\/p>\n<ul class=\"list-disc ml-6 my-6\">\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Less boilerplate code<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Easy to test (inject mock services)<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Easy to change implementations (just provide a different service)<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Automatic handling of circular dependencies<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h2 class=\"text-3xl font-semibold mt-14 mb-8 \">Real-World Production Features<\/h2>\n<p class=\" text-lg my-6\">A real-world backend needs more than just routes. NestJS is designed to handle these concerns cleanly.<\/p>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">Authentication and Authorization<\/h3>\n<p class=\" text-lg my-6\"><strong>Authentication:<\/strong> Who is the user? <strong>Authorization:<\/strong> What can the user do?<\/p>\n<p class=\" text-lg my-6\"><strong>NestJS Approach:<\/strong><\/p>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-typescript whitespace-pre-wrap break-words text-gray-300\"><span class=\"hljs-comment\">\/\/ jwt.strategy.ts - Define how to validate JWT tokens<\/span>\n<span class=\"hljs-meta\">@Injectable<\/span>()\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">JwtStrategy<\/span> <span class=\"hljs-keyword\">extends<\/span> <span class=\"hljs-title class_ inherited__\">PassportStrategy<\/span>(<span class=\"hljs-title class_\">Strategy<\/span>) {\n    <span class=\"hljs-title function_\">constructor<\/span>(<span class=\"hljs-params\"><span class=\"hljs-keyword\">private<\/span> <span class=\"hljs-attr\">configService<\/span>: <span class=\"hljs-title class_\">ConfigService<\/span><\/span>) {\n        <span class=\"hljs-variable language_\">super<\/span>({\n            <span class=\"hljs-attr\">jwtFromRequest<\/span>: <span class=\"hljs-title class_\">ExtractJwt<\/span>.<span class=\"hljs-title function_\">fromAuthHeaderAsBearerToken<\/span>(),\n            <span class=\"hljs-attr\">ignoreExpiration<\/span>: <span class=\"hljs-literal\">false<\/span>,\n            <span class=\"hljs-attr\">secretOrKey<\/span>: configService.<span class=\"hljs-title function_\">get<\/span>(<span class=\"hljs-string\">'JWT_SECRET'<\/span>),\n        });\n    }\n\n    <span class=\"hljs-title function_\">validate<\/span>(<span class=\"hljs-params\"><span class=\"hljs-attr\">payload<\/span>: <span class=\"hljs-built_in\">any<\/span><\/span>) {\n        <span class=\"hljs-keyword\">return<\/span> { <span class=\"hljs-attr\">userId<\/span>: payload.<span class=\"hljs-property\">sub<\/span>, <span class=\"hljs-attr\">username<\/span>: payload.<span class=\"hljs-property\">username<\/span> };\n    }\n}\n\n<span class=\"hljs-comment\">\/\/ jwt-auth.guard.ts - Protect routes with JWT<\/span>\n<span class=\"hljs-meta\">@Injectable<\/span>()\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">JwtAuthGuard<\/span> <span class=\"hljs-keyword\">extends<\/span> <span class=\"hljs-title class_ inherited__\">AuthGuard<\/span>(<span class=\"hljs-string\">'jwt'<\/span>) {}\n\n<span class=\"hljs-comment\">\/\/ user.controller.ts - Use the guard<\/span>\n<span class=\"hljs-meta\">@Controller<\/span>(<span class=\"hljs-string\">'users'<\/span>)\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">UserController<\/span> {\n    <span class=\"hljs-meta\">@Get<\/span>(<span class=\"hljs-string\">'profile'<\/span>)\n    <span class=\"hljs-meta\">@UseGuards<\/span>(<span class=\"hljs-title class_\">JwtAuthGuard<\/span>)  <span class=\"hljs-comment\">\/\/ Require JWT token<\/span>\n    <span class=\"hljs-title function_\">getProfile<\/span>(<span class=\"hljs-params\"><span class=\"hljs-meta\">@Request<\/span>() req<\/span>) {\n        <span class=\"hljs-keyword\">return<\/span> req.<span class=\"hljs-property\">user<\/span>;\n    }\n}\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<p class=\" text-lg my-6\"><strong>Benefits:<\/strong><\/p>\n<ul class=\"list-disc ml-6 my-6\">\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Authentication is centralized<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Guards are reusable across controllers<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Easy to test (mock the guard)<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Consistent across the application<\/p>\n<\/li>\n<\/ul>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">Data Validation<\/h3>\n<p class=\" text-lg my-6\">NestJS automatically validates request data using DTOs and Pipes.<\/p>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-typescript whitespace-pre-wrap break-words text-gray-300\"><span class=\"hljs-comment\">\/\/ create-user.dto.ts - Define expected request structure<\/span>\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">CreateUserDto<\/span> {\n    <span class=\"hljs-meta\">@IsEmail<\/span>()\n    <span class=\"hljs-attr\">email<\/span>: <span class=\"hljs-built_in\">string<\/span>;\n\n    <span class=\"hljs-meta\">@MinLength<\/span>(<span class=\"hljs-number\">6<\/span>)\n    <span class=\"hljs-attr\">password<\/span>: <span class=\"hljs-built_in\">string<\/span>;\n\n    <span class=\"hljs-meta\">@IsOptional<\/span>()\n    <span class=\"hljs-meta\">@IsPhoneNumber<\/span>()\n    <span class=\"hljs-attr\">phone<\/span>: <span class=\"hljs-built_in\">string<\/span>;\n}\n\n<span class=\"hljs-comment\">\/\/ user.controller.ts - Validate automatically<\/span>\n<span class=\"hljs-meta\">@Controller<\/span>(<span class=\"hljs-string\">'users'<\/span>)\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">UserController<\/span> {\n    <span class=\"hljs-meta\">@Post<\/span>()\n    <span class=\"hljs-title function_\">createUser<\/span>(<span class=\"hljs-params\"><span class=\"hljs-meta\">@Body<\/span>() <span class=\"hljs-attr\">createUserDto<\/span>: <span class=\"hljs-title class_\">CreateUserDto<\/span><\/span>) {\n        <span class=\"hljs-comment\">\/\/ \u2705 createUserDto is validated and typed<\/span>\n        <span class=\"hljs-comment\">\/\/ Invalid requests are rejected automatically<\/span>\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">userService<\/span>.<span class=\"hljs-title function_\">create<\/span>(createUserDto);\n    }\n}\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<p class=\" text-lg my-6\"><strong>What NestJS does:<\/strong><\/p>\n<ol class=\"list-decimal ml-6 my-6\">\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Receives request<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Validates against CreateUserDto schema<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Transforms to typed object<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Rejects if invalid<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Passes to controller only if valid<\/p>\n<\/li>\n<\/ol>\n<p class=\" text-lg my-6\"><strong>Benefits:<\/strong><\/p>\n<ul class=\"list-disc ml-6 my-6\">\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Validation is declarative<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Errors are consistent<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">No manual validation code in controllers<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Type-safe throughout<\/p>\n<\/li>\n<\/ul>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">Database Integration<\/h3>\n<p class=\" text-lg my-6\">NestJS integrates seamlessly with popular ORMs like TypeORM and Prisma.<\/p>\n<p class=\" text-lg my-6\"><strong>Example with TypeORM:<\/strong><\/p>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-typescript whitespace-pre-wrap break-words text-gray-300\"><span class=\"hljs-comment\">\/\/ user.entity.ts - Database model<\/span>\n<span class=\"hljs-meta\">@Entity<\/span>()\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">User<\/span> {\n    <span class=\"hljs-meta\">@PrimaryGeneratedColumn<\/span>(<span class=\"hljs-string\">'uuid'<\/span>)\n    <span class=\"hljs-attr\">id<\/span>: <span class=\"hljs-built_in\">string<\/span>;\n\n    <span class=\"hljs-meta\">@Column<\/span>({ <span class=\"hljs-attr\">unique<\/span>: <span class=\"hljs-literal\">true<\/span> })\n    <span class=\"hljs-attr\">email<\/span>: <span class=\"hljs-built_in\">string<\/span>;\n\n    <span class=\"hljs-meta\">@Column<\/span>()\n    <span class=\"hljs-attr\">password<\/span>: <span class=\"hljs-built_in\">string<\/span>;\n\n    <span class=\"hljs-meta\">@Column<\/span>({ <span class=\"hljs-attr\">default<\/span>: <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">Date<\/span>() })\n    <span class=\"hljs-attr\">createdAt<\/span>: <span class=\"hljs-title class_\">Date<\/span>;\n}\n\n<span class=\"hljs-comment\">\/\/ user.module.ts - Register with database<\/span>\n<span class=\"hljs-meta\">@Module<\/span>({\n    <span class=\"hljs-attr\">imports<\/span>: [<span class=\"hljs-title class_\">TypeOrmModule<\/span>.<span class=\"hljs-title function_\">forFeature<\/span>([<span class=\"hljs-title class_\">User<\/span>])],\n    <span class=\"hljs-attr\">controllers<\/span>: [<span class=\"hljs-title class_\">UserController<\/span>],\n    <span class=\"hljs-attr\">providers<\/span>: [<span class=\"hljs-title class_\">UserService<\/span>],\n})\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">UserModule<\/span> {}\n\n<span class=\"hljs-comment\">\/\/ user.service.ts - Use automatically<\/span>\n<span class=\"hljs-meta\">@Injectable<\/span>()\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">UserService<\/span> {\n    <span class=\"hljs-title function_\">constructor<\/span>(<span class=\"hljs-params\">\n        <span class=\"hljs-meta\">@InjectRepository<\/span>(User)\n        <span class=\"hljs-keyword\">private<\/span> <span class=\"hljs-attr\">userRepository<\/span>: <span class=\"hljs-title class_\">Repository<\/span>&lt;<span class=\"hljs-title class_\">User<\/span>&gt;,\n    <\/span>) {}\n\n    <span class=\"hljs-title function_\">findAll<\/span>() {\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">userRepository<\/span>.<span class=\"hljs-title function_\">find<\/span>();\n    }\n\n    <span class=\"hljs-title function_\">findById<\/span>(<span class=\"hljs-params\"><span class=\"hljs-attr\">id<\/span>: <span class=\"hljs-built_in\">string<\/span><\/span>) {\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">userRepository<\/span>.<span class=\"hljs-title function_\">findOne<\/span>({ <span class=\"hljs-attr\">where<\/span>: { id } });\n    }\n\n    <span class=\"hljs-title function_\">create<\/span>(<span class=\"hljs-params\"><span class=\"hljs-attr\">data<\/span>: <span class=\"hljs-title class_\">CreateUserDto<\/span><\/span>) {\n        <span class=\"hljs-keyword\">const<\/span> user = <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">userRepository<\/span>.<span class=\"hljs-title function_\">create<\/span>(data);\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">userRepository<\/span>.<span class=\"hljs-title function_\">save<\/span>(user);\n    }\n}\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<p class=\" text-lg my-6\"><strong>Benefits:<\/strong><\/p>\n<ul class=\"list-disc ml-6 my-6\">\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Type-safe database queries<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Schema is defined in code<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Migrations are managed<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Relationship management is automatic<\/p>\n<\/li>\n<\/ul>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">Error Handling<\/h3>\n<p class=\" text-lg my-6\">Errors are handled consistently through Exception Filters.<\/p>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-typescript whitespace-pre-wrap break-words text-gray-300\"><span class=\"hljs-comment\">\/\/ http-exception.filter.ts - Global error handler<\/span>\n<span class=\"hljs-meta\">@Catch<\/span>(<span class=\"hljs-title class_\">HttpException<\/span>)\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">HttpExceptionFilter<\/span> <span class=\"hljs-keyword\">implements<\/span> <span class=\"hljs-title class_\">ExceptionFilter<\/span> {\n    <span class=\"hljs-keyword\">catch<\/span>(<span class=\"hljs-attr\">exception<\/span>: <span class=\"hljs-title class_\">HttpException<\/span>, <span class=\"hljs-attr\">host<\/span>: <span class=\"hljs-title class_\">ArgumentsHost<\/span>) {\n        <span class=\"hljs-keyword\">const<\/span> ctx = host.<span class=\"hljs-title function_\">switchToHttp<\/span>();\n        <span class=\"hljs-keyword\">const<\/span> response = ctx.<span class=\"hljs-property\">getResponse<\/span>&lt;<span class=\"hljs-title class_\">Response<\/span>&gt;();\n        <span class=\"hljs-keyword\">const<\/span> status = exception.<span class=\"hljs-title function_\">getStatus<\/span>();\n        <span class=\"hljs-keyword\">const<\/span> exceptionResponse = exception.<span class=\"hljs-title function_\">getResponse<\/span>();\n\n        response\n            .<span class=\"hljs-title function_\">status<\/span>(status)\n            .<span class=\"hljs-title function_\">json<\/span>({\n                <span class=\"hljs-attr\">statusCode<\/span>: status,\n                <span class=\"hljs-attr\">timestamp<\/span>: <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">Date<\/span>().<span class=\"hljs-title function_\">toISOString<\/span>(),\n                <span class=\"hljs-attr\">path<\/span>: ctx.<span class=\"hljs-title function_\">getRequest<\/span>().<span class=\"hljs-property\">url<\/span>,\n                <span class=\"hljs-attr\">message<\/span>: exceptionResponse,\n            });\n    }\n}\n\n<span class=\"hljs-comment\">\/\/ main.ts - Register globally<\/span>\n<span class=\"hljs-keyword\">const<\/span> app = <span class=\"hljs-keyword\">await<\/span> <span class=\"hljs-title class_\">NestFactory<\/span>.<span class=\"hljs-title function_\">create<\/span>(<span class=\"hljs-title class_\">AppModule<\/span>);\napp.<span class=\"hljs-title function_\">useGlobalFilters<\/span>(<span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">HttpExceptionFilter<\/span>());\n<span class=\"hljs-keyword\">await<\/span> app.<span class=\"hljs-title function_\">listen<\/span>(<span class=\"hljs-number\">3000<\/span>);\n\n<span class=\"hljs-comment\">\/\/ user.controller.ts - Throw errors, they're handled automatically<\/span>\n<span class=\"hljs-meta\">@Controller<\/span>(<span class=\"hljs-string\">'users'<\/span>)\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">UserController<\/span> {\n    <span class=\"hljs-meta\">@Get<\/span>(<span class=\"hljs-string\">':id'<\/span>)\n    <span class=\"hljs-keyword\">async<\/span> <span class=\"hljs-title function_\">getUser<\/span>(<span class=\"hljs-params\"><span class=\"hljs-meta\">@Param<\/span>(<span class=\"hljs-string\">'id'<\/span>) <span class=\"hljs-attr\">id<\/span>: <span class=\"hljs-built_in\">string<\/span><\/span>) {\n        <span class=\"hljs-keyword\">const<\/span> user = <span class=\"hljs-keyword\">await<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">userService<\/span>.<span class=\"hljs-title function_\">findById<\/span>(id);\n        <span class=\"hljs-keyword\">if<\/span> (!user) {\n            <span class=\"hljs-keyword\">throw<\/span> <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">NotFoundException<\/span>(<span class=\"hljs-string\">'User not found'<\/span>);\n        }\n        <span class=\"hljs-keyword\">return<\/span> user;\n    }\n}\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<p class=\" text-lg my-6\"><strong>Benefits:<\/strong><\/p>\n<ul class=\"list-disc ml-6 my-6\">\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Errors are handled consistently<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">No try-catch blocks everywhere<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Error responses are formatted uniformly<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Logging is centralized<\/p>\n<\/li>\n<\/ul>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">Logging<\/h3>\n<p class=\" text-lg my-6\">NestJS provides a built-in logger and integrates with popular logging services.<\/p>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-typescript whitespace-pre-wrap break-words text-gray-300\"><span class=\"hljs-meta\">@Injectable<\/span>()\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">UserService<\/span> {\n    <span class=\"hljs-keyword\">private<\/span> logger = <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">Logger<\/span>(<span class=\"hljs-title class_\">UserService<\/span>.<span class=\"hljs-property\">name<\/span>);\n\n    <span class=\"hljs-title function_\">findAll<\/span>() {\n        <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">logger<\/span>.<span class=\"hljs-title function_\">log<\/span>(<span class=\"hljs-string\">'Fetching all users'<\/span>);\n        <span class=\"hljs-keyword\">const<\/span> users = <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">userRepository<\/span>.<span class=\"hljs-title function_\">find<\/span>();\n        <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">logger<\/span>.<span class=\"hljs-title function_\">debug<\/span>(<span class=\"hljs-string\">`Found <span class=\"hljs-subst\">${users.length}<\/span> users`<\/span>);\n        <span class=\"hljs-keyword\">return<\/span> users;\n    }\n\n    <span class=\"hljs-keyword\">async<\/span> <span class=\"hljs-title function_\">createUser<\/span>(<span class=\"hljs-params\"><span class=\"hljs-attr\">createUserDto<\/span>: <span class=\"hljs-title class_\">CreateUserDto<\/span><\/span>) {\n        <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">logger<\/span>.<span class=\"hljs-title function_\">log<\/span>(<span class=\"hljs-string\">`Creating user with email: <span class=\"hljs-subst\">${createUserDto.email}<\/span>`<\/span>);\n        <span class=\"hljs-keyword\">try<\/span> {\n            <span class=\"hljs-keyword\">const<\/span> user = <span class=\"hljs-keyword\">await<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">userRepository<\/span>.<span class=\"hljs-title function_\">create<\/span>(createUserDto);\n            <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">logger<\/span>.<span class=\"hljs-title function_\">log<\/span>(<span class=\"hljs-string\">`User created with ID: <span class=\"hljs-subst\">${user.id}<\/span>`<\/span>);\n            <span class=\"hljs-keyword\">return<\/span> user;\n        } <span class=\"hljs-keyword\">catch<\/span> (error) {\n            <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">logger<\/span>.<span class=\"hljs-title function_\">error<\/span>(<span class=\"hljs-string\">`Failed to create user: <span class=\"hljs-subst\">${error.message}<\/span>`<\/span>);\n            <span class=\"hljs-keyword\">throw<\/span> error;\n        }\n    }\n}\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<p class=\" text-lg my-6\"><strong>Benefits:<\/strong><\/p>\n<ul class=\"list-disc ml-6 my-6\">\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Structured logging<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Different log levels (log, debug, warn, error)<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Integrated across the application<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Easy to export to logging services (Winston, Bunyan, etc.)<\/p>\n<\/li>\n<\/ul>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">Real-Time Communication (WebSockets)<\/h3>\n<p class=\" text-lg my-6\">For features like notifications and live updates, NestJS supports WebSockets as a first-class feature.<\/p>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-typescript whitespace-pre-wrap break-words text-gray-300\"><span class=\"hljs-meta\">@WebSocketGateway<\/span>()\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">NotificationGateway<\/span> <span class=\"hljs-keyword\">implements<\/span> <span class=\"hljs-title class_\">OnGatewayConnection<\/span> {\n    <span class=\"hljs-meta\">@WebSocketServer<\/span>()\n    <span class=\"hljs-attr\">server<\/span>: <span class=\"hljs-title class_\">Server<\/span>;\n\n    <span class=\"hljs-title function_\">handleConnection<\/span>(<span class=\"hljs-params\"><span class=\"hljs-attr\">client<\/span>: <span class=\"hljs-title class_\">Socket<\/span><\/span>) {\n        <span class=\"hljs-variable language_\">console<\/span>.<span class=\"hljs-title function_\">log<\/span>(<span class=\"hljs-string\">`Client connected: <span class=\"hljs-subst\">${client.id}<\/span>`<\/span>);\n    }\n\n    <span class=\"hljs-meta\">@SubscribeMessage<\/span>(<span class=\"hljs-string\">'message'<\/span>)\n    <span class=\"hljs-title function_\">handleMessage<\/span>(<span class=\"hljs-params\"><span class=\"hljs-attr\">client<\/span>: <span class=\"hljs-title class_\">Socket<\/span>, <span class=\"hljs-attr\">data<\/span>: <span class=\"hljs-built_in\">string<\/span><\/span>) {\n        <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">server<\/span>.<span class=\"hljs-title function_\">emit<\/span>(<span class=\"hljs-string\">'message'<\/span>, data);\n    }\n\n    <span class=\"hljs-title function_\">sendNotification<\/span>(<span class=\"hljs-params\"><span class=\"hljs-attr\">userId<\/span>: <span class=\"hljs-built_in\">string<\/span>, <span class=\"hljs-attr\">message<\/span>: <span class=\"hljs-built_in\">string<\/span><\/span>) {\n        <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">server<\/span>.<span class=\"hljs-title function_\">to<\/span>(userId).<span class=\"hljs-title function_\">emit<\/span>(<span class=\"hljs-string\">'notification'<\/span>, message);\n    }\n}\n\n<span class=\"hljs-comment\">\/\/ user.service.ts<\/span>\n<span class=\"hljs-meta\">@Injectable<\/span>()\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">UserService<\/span> {\n    <span class=\"hljs-title function_\">constructor<\/span>(<span class=\"hljs-params\"><span class=\"hljs-keyword\">private<\/span> <span class=\"hljs-attr\">notificationGateway<\/span>: <span class=\"hljs-title class_\">NotificationGateway<\/span><\/span>) {}\n\n    <span class=\"hljs-keyword\">async<\/span> <span class=\"hljs-title function_\">updateUser<\/span>(<span class=\"hljs-params\"><span class=\"hljs-attr\">id<\/span>: <span class=\"hljs-built_in\">string<\/span>, <span class=\"hljs-attr\">data<\/span>: <span class=\"hljs-title class_\">UpdateUserDto<\/span><\/span>) {\n        <span class=\"hljs-keyword\">const<\/span> user = <span class=\"hljs-keyword\">await<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">userRepository<\/span>.<span class=\"hljs-title function_\">update<\/span>(id, data);\n        <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">notificationGateway<\/span>.<span class=\"hljs-title function_\">sendNotification<\/span>(id, <span class=\"hljs-string\">'Profile updated'<\/span>);\n        <span class=\"hljs-keyword\">return<\/span> user;\n    }\n}\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<p class=\" text-lg my-6\"><strong>Benefits:<\/strong><\/p>\n<ul class=\"list-disc ml-6 my-6\">\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Real-time features are first-class<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Clean separation from HTTP logic<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Easy to test<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Scalable with message queues<\/p>\n<\/li>\n<\/ul>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">Rate Limiting<\/h3>\n<p class=\" text-lg my-6\">Protect APIs from abuse with rate limiting.<\/p>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-typescript whitespace-pre-wrap break-words text-gray-300\"><span class=\"hljs-comment\">\/\/ throttler.guard.ts<\/span>\n<span class=\"hljs-meta\">@Injectable<\/span>()\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">ThrottlerGuard<\/span> <span class=\"hljs-keyword\">extends<\/span> <span class=\"hljs-title class_ inherited__\">AbstractHttpGuard<\/span> {\n    <span class=\"hljs-keyword\">async<\/span> <span class=\"hljs-title function_\">canActivate<\/span>(<span class=\"hljs-attr\">context<\/span>: <span class=\"hljs-title class_\">ExecutionContext<\/span>): <span class=\"hljs-title class_\">Promise<\/span>&lt;<span class=\"hljs-built_in\">boolean<\/span>&gt; {\n        <span class=\"hljs-comment\">\/\/ Limit to 10 requests per minute<\/span>\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable language_\">super<\/span>.<span class=\"hljs-title function_\">canActivate<\/span>(context);\n    }\n}\n\n<span class=\"hljs-comment\">\/\/ user.controller.ts<\/span>\n<span class=\"hljs-meta\">@Controller<\/span>(<span class=\"hljs-string\">'users'<\/span>)\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">UserController<\/span> {\n    <span class=\"hljs-meta\">@Get<\/span>()\n    <span class=\"hljs-meta\">@UseGuards<\/span>(<span class=\"hljs-title class_\">ThrottlerGuard<\/span>)\n    <span class=\"hljs-title function_\">getUsers<\/span>() {\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">userService<\/span>.<span class=\"hljs-title function_\">findAll<\/span>();\n    }\n\n    <span class=\"hljs-meta\">@Post<\/span>()\n    <span class=\"hljs-meta\">@UseGuards<\/span>(<span class=\"hljs-title class_\">ThrottlerGuard<\/span>)\n    <span class=\"hljs-title function_\">createUser<\/span>(<span class=\"hljs-params\"><span class=\"hljs-meta\">@Body<\/span>() <span class=\"hljs-attr\">createUserDto<\/span>: <span class=\"hljs-title class_\">CreateUserDto<\/span><\/span>) {\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">userService<\/span>.<span class=\"hljs-title function_\">create<\/span>(createUserDto);\n    }\n}\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<hr \/>\n<h2 class=\"text-3xl font-semibold mt-14 mb-8 \">Getting Started with NestJS<\/h2>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">Prerequisites<\/h3>\n<p class=\" text-lg my-6\">You need:<\/p>\n<ul class=\"list-disc ml-6 my-6\">\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>Node.js 18+<\/strong> (check with <code class=\"break-words rounded bg-[#24292E] px-2 py-1 text-[#EEEEEE]\">node -v<\/code>)<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>npm<\/strong> or <strong>yarn<\/strong> (comes with Node.js)<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>Code editor<\/strong> (VS Code recommended)<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>Basic TypeScript knowledge<\/strong> (NestJS teaches you as you go)<\/p>\n<\/li>\n<\/ul>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">Step 1: Install NestJS CLI<\/h3>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-bash whitespace-pre-wrap break-words text-gray-300\">npm install -g @nestjs\/cli\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">Step 2: Create a New Project<\/h3>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-bash whitespace-pre-wrap break-words text-gray-300\">nest new my-backend\n<span class=\"hljs-built_in\">cd<\/span> my-backend\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<p class=\" text-lg my-6\"><strong>Choose during setup:<\/strong><\/p>\n<ul class=\"list-disc ml-6 my-6\">\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Package manager: npm, yarn, or pnpm<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Default options are fine for learning<\/p>\n<\/li>\n<\/ul>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">Step 3: Understand the Project Structure<\/h3>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-json whitespace-pre-wrap break-words text-gray-300\">src\/\n\u251c\u2500\u2500 main.ts                 # Application entry point\n\u251c\u2500\u2500 app.module.ts          # Root module\n\u251c\u2500\u2500 app.controller.ts      # Example controller\n\u251c\u2500\u2500 app.service.ts         # Example service\ntest\/                       # Test files\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">Step 4: Run the Application<\/h3>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-bash whitespace-pre-wrap break-words text-gray-300\">npm run start:dev\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<p class=\" text-lg my-6\">Visit <code class=\"break-words rounded bg-[#24292E] px-2 py-1 text-[#EEEEEE]\">http:\/\/localhost:3000<\/code> in your browser.<\/p>\n<p class=\" text-lg my-6\">You should see: <code class=\"break-words rounded bg-[#24292E] px-2 py-1 text-[#EEEEEE]\">Hello World!<\/code><\/p>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">Step 5: Generate Your First Feature<\/h3>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-bash whitespace-pre-wrap break-words text-gray-300\"><span class=\"hljs-comment\"># Generate a complete user module (controller + service + module)<\/span>\nnest generate module <span class=\"hljs-built_in\">users<\/span>\nnest generate controller <span class=\"hljs-built_in\">users<\/span>\nnest generate service <span class=\"hljs-built_in\">users<\/span>\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<p class=\" text-lg my-6\">This creates:<\/p>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-json whitespace-pre-wrap break-words text-gray-300\">src\/users\/\n\u251c\u2500\u2500 users.module.ts\n\u251c\u2500\u2500 users.controller.ts\n\u251c\u2500\u2500 users.service.ts\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">Step 6: Create a Database Entity<\/h3>\n<p class=\" text-lg my-6\">If using TypeORM:<\/p>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-typescript whitespace-pre-wrap break-words text-gray-300\"><span class=\"hljs-comment\">\/\/ users\/user.entity.ts<\/span>\n<span class=\"hljs-keyword\">import<\/span> { <span class=\"hljs-title class_\">Entity<\/span>, <span class=\"hljs-title class_\">PrimaryGeneratedColumn<\/span>, <span class=\"hljs-title class_\">Column<\/span> } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'typeorm'<\/span>;\n\n<span class=\"hljs-meta\">@Entity<\/span>()\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">User<\/span> {\n    <span class=\"hljs-meta\">@PrimaryGeneratedColumn<\/span>()\n    <span class=\"hljs-attr\">id<\/span>: <span class=\"hljs-built_in\">number<\/span>;\n\n    <span class=\"hljs-meta\">@Column<\/span>()\n    <span class=\"hljs-attr\">name<\/span>: <span class=\"hljs-built_in\">string<\/span>;\n\n    <span class=\"hljs-meta\">@Column<\/span>({ <span class=\"hljs-attr\">unique<\/span>: <span class=\"hljs-literal\">true<\/span> })\n    <span class=\"hljs-attr\">email<\/span>: <span class=\"hljs-built_in\">string<\/span>;\n\n    <span class=\"hljs-meta\">@Column<\/span>()\n    <span class=\"hljs-attr\">password<\/span>: <span class=\"hljs-built_in\">string<\/span>;\n}\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">Step 7: Create a DTO (Data Transfer Object)<\/h3>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-typescript whitespace-pre-wrap break-words text-gray-300\"><span class=\"hljs-comment\">\/\/ users\/dto\/create-user.dto.ts<\/span>\n<span class=\"hljs-keyword\">import<\/span> { <span class=\"hljs-title class_\">IsEmail<\/span>, <span class=\"hljs-title class_\">MinLength<\/span> } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'class-validator'<\/span>;\n\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">CreateUserDto<\/span> {\n    <span class=\"hljs-attr\">name<\/span>: <span class=\"hljs-built_in\">string<\/span>;\n\n    <span class=\"hljs-meta\">@IsEmail<\/span>()\n    <span class=\"hljs-attr\">email<\/span>: <span class=\"hljs-built_in\">string<\/span>;\n\n    <span class=\"hljs-meta\">@MinLength<\/span>(<span class=\"hljs-number\">6<\/span>)\n    <span class=\"hljs-attr\">password<\/span>: <span class=\"hljs-built_in\">string<\/span>;\n}\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">Step 8: Implement the Service<\/h3>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-typescript whitespace-pre-wrap break-words text-gray-300\"><span class=\"hljs-comment\">\/\/ users\/users.service.ts<\/span>\n<span class=\"hljs-keyword\">import<\/span> { <span class=\"hljs-title class_\">Injectable<\/span> } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'@nestjs\/common'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { <span class=\"hljs-title class_\">InjectRepository<\/span> } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'@nestjs\/typeorm'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { <span class=\"hljs-title class_\">Repository<\/span> } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'typeorm'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { <span class=\"hljs-title class_\">User<\/span> } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'.\/user.entity'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { <span class=\"hljs-title class_\">CreateUserDto<\/span> } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'.\/dto\/create-user.dto'<\/span>;\n\n<span class=\"hljs-meta\">@Injectable<\/span>()\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">UsersService<\/span> {\n    <span class=\"hljs-title function_\">constructor<\/span>(<span class=\"hljs-params\">\n        <span class=\"hljs-meta\">@InjectRepository<\/span>(User)\n        <span class=\"hljs-keyword\">private<\/span> <span class=\"hljs-attr\">usersRepository<\/span>: <span class=\"hljs-title class_\">Repository<\/span>&lt;<span class=\"hljs-title class_\">User<\/span>&gt;,\n    <\/span>) {}\n\n    <span class=\"hljs-title function_\">create<\/span>(<span class=\"hljs-params\"><span class=\"hljs-attr\">createUserDto<\/span>: <span class=\"hljs-title class_\">CreateUserDto<\/span><\/span>) {\n        <span class=\"hljs-keyword\">const<\/span> user = <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">usersRepository<\/span>.<span class=\"hljs-title function_\">create<\/span>(createUserDto);\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">usersRepository<\/span>.<span class=\"hljs-title function_\">save<\/span>(user);\n    }\n\n    <span class=\"hljs-title function_\">findAll<\/span>() {\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">usersRepository<\/span>.<span class=\"hljs-title function_\">find<\/span>();\n    }\n\n    <span class=\"hljs-title function_\">findOne<\/span>(<span class=\"hljs-params\"><span class=\"hljs-attr\">id<\/span>: <span class=\"hljs-built_in\">number<\/span><\/span>) {\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">usersRepository<\/span>.<span class=\"hljs-title function_\">findOne<\/span>({ <span class=\"hljs-attr\">where<\/span>: { id } });\n    }\n\n    <span class=\"hljs-title function_\">update<\/span>(<span class=\"hljs-params\"><span class=\"hljs-attr\">id<\/span>: <span class=\"hljs-built_in\">number<\/span>, <span class=\"hljs-attr\">updateUserDto<\/span>: <span class=\"hljs-title class_\">CreateUserDto<\/span><\/span>) {\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">usersRepository<\/span>.<span class=\"hljs-title function_\">update<\/span>(id, updateUserDto);\n    }\n\n    <span class=\"hljs-title function_\">remove<\/span>(<span class=\"hljs-params\"><span class=\"hljs-attr\">id<\/span>: <span class=\"hljs-built_in\">number<\/span><\/span>) {\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">usersRepository<\/span>.<span class=\"hljs-title function_\">delete<\/span>(id);\n    }\n}\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">Step 9: Implement the Controller<\/h3>\n<div class=\"relative group\">\n<pre class=\"relative bg-[#1a1a1a] border border-gray-700 rounded-lg overflow-x-auto my-8 p-6\"><code class=\"hljs language-typescript whitespace-pre-wrap break-words text-gray-300\"><span class=\"hljs-comment\">\/\/ users\/users.controller.ts<\/span>\n<span class=\"hljs-keyword\">import<\/span> { <span class=\"hljs-title class_\">Controller<\/span>, <span class=\"hljs-title class_\">Get<\/span>, <span class=\"hljs-title class_\">Post<\/span>, <span class=\"hljs-title class_\">Body<\/span>, <span class=\"hljs-title class_\">Param<\/span>, <span class=\"hljs-title class_\">Delete<\/span> } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'@nestjs\/common'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { <span class=\"hljs-title class_\">UsersService<\/span> } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'.\/users.service'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { <span class=\"hljs-title class_\">CreateUserDto<\/span> } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'.\/dto\/create-user.dto'<\/span>;\n\n<span class=\"hljs-meta\">@Controller<\/span>(<span class=\"hljs-string\">'users'<\/span>)\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">UsersController<\/span> {\n    <span class=\"hljs-title function_\">constructor<\/span>(<span class=\"hljs-params\"><span class=\"hljs-keyword\">private<\/span> <span class=\"hljs-attr\">usersService<\/span>: <span class=\"hljs-title class_\">UsersService<\/span><\/span>) {}\n\n    <span class=\"hljs-meta\">@Post<\/span>()\n    <span class=\"hljs-title function_\">create<\/span>(<span class=\"hljs-params\"><span class=\"hljs-meta\">@Body<\/span>() <span class=\"hljs-attr\">createUserDto<\/span>: <span class=\"hljs-title class_\">CreateUserDto<\/span><\/span>) {\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">usersService<\/span>.<span class=\"hljs-title function_\">create<\/span>(createUserDto);\n    }\n\n    <span class=\"hljs-meta\">@Get<\/span>()\n    <span class=\"hljs-title function_\">findAll<\/span>() {\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">usersService<\/span>.<span class=\"hljs-title function_\">findAll<\/span>();\n    }\n\n    <span class=\"hljs-meta\">@Get<\/span>(<span class=\"hljs-string\">':id'<\/span>)\n    <span class=\"hljs-title function_\">findOne<\/span>(<span class=\"hljs-params\"><span class=\"hljs-meta\">@Param<\/span>(<span class=\"hljs-string\">'id'<\/span>) <span class=\"hljs-attr\">id<\/span>: <span class=\"hljs-built_in\">string<\/span><\/span>) {\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">usersService<\/span>.<span class=\"hljs-title function_\">findOne<\/span>(+id);\n    }\n\n    <span class=\"hljs-meta\">@Delete<\/span>(<span class=\"hljs-string\">':id'<\/span>)\n    <span class=\"hljs-title function_\">remove<\/span>(<span class=\"hljs-params\"><span class=\"hljs-meta\">@Param<\/span>(<span class=\"hljs-string\">'id'<\/span>) <span class=\"hljs-attr\">id<\/span>: <span class=\"hljs-built_in\">string<\/span><\/span>) {\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable language_\">this<\/span>.<span class=\"hljs-property\">usersService<\/span>.<span class=\"hljs-title function_\">remove<\/span>(+id);\n    }\n}\n<\/code><\/pre>\n<p><button class=\"absolute top-4 cursor-pointer right-4 p-2 rounded-md bg-[#24292e] hover:bg-gray-700 border border-gray-600 opacity-0 group-hover:opacity-100 transition-opacity duration-200\" title=\"Copy code\"><\/button><\/div>\n<hr \/>\n<h2 class=\"text-3xl font-semibold mt-14 mb-8 \">NestJS vs Express: A Comparison<\/h2>\n<table>\n<thead>\n<tr>\n<th>Feature<\/th>\n<th>Express<\/th>\n<th>NestJS<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>Learning Curve<\/strong><\/td>\n<td>Shallow (easy to start)<\/td>\n<td>Moderate (more concepts)<\/td>\n<\/tr>\n<tr>\n<td><strong>Structure<\/strong><\/td>\n<td>You decide<\/td>\n<td>Opinionated, enforced<\/td>\n<\/tr>\n<tr>\n<td><strong>Scalability<\/strong><\/td>\n<td>Depends on team discipline<\/td>\n<td>Built-in scalability patterns<\/td>\n<\/tr>\n<tr>\n<td><strong>TypeScript<\/strong><\/td>\n<td>Optional, needs setup<\/td>\n<td>First-class, built-in<\/td>\n<\/tr>\n<tr>\n<td><strong>Dependency Injection<\/strong><\/td>\n<td>No (manual)<\/td>\n<td>Yes (automatic)<\/td>\n<\/tr>\n<tr>\n<td><strong>Validation<\/strong><\/td>\n<td>Manual or via middleware<\/td>\n<td>Built-in with Pipes<\/td>\n<\/tr>\n<tr>\n<td><strong>Error Handling<\/strong><\/td>\n<td>Manual everywhere<\/td>\n<td>Centralized Exception Filters<\/td>\n<\/tr>\n<tr>\n<td><strong>Testing<\/strong><\/td>\n<td>Harder (HTTP layer tangled)<\/td>\n<td>Easier (clean separation)<\/td>\n<\/tr>\n<tr>\n<td><strong>Authentication<\/strong><\/td>\n<td>Manual or via passport<\/td>\n<td>Guards + Strategies<\/td>\n<\/tr>\n<tr>\n<td><strong>Database<\/strong><\/td>\n<td>Any ORM, you manage<\/td>\n<td>Integrated TypeORM\/Prisma<\/td>\n<\/tr>\n<tr>\n<td><strong>Suitable For<\/strong><\/td>\n<td>Small projects, APIs<\/td>\n<td>Production systems, teams<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\" text-lg my-6\"><strong>When to use Express:<\/strong><\/p>\n<ul class=\"list-disc ml-6 my-6\">\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Small projects<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Prototypes<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Learning Node.js basics<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">When you want complete flexibility<\/p>\n<\/li>\n<\/ul>\n<p class=\" text-lg my-6\"><strong>When to use NestJS:<\/strong><\/p>\n<ul class=\"list-disc ml-6 my-6\">\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Production applications<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Large teams<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Long-term maintenance<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Microservices<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\">Enterprise requirements<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h2 class=\"text-3xl font-semibold mt-14 mb-8 \">Key Takeaways<\/h2>\n<ol class=\"list-decimal ml-6 my-6\">\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>NestJS brings structure to Node.js development<\/strong> &#8211; No more figuring out how to organize your code. Follow the pattern.<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>Dependency Injection simplifies everything<\/strong> &#8211; Easier to test, easier to refactor, less boilerplate.<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>TypeScript first means fewer bugs<\/strong> &#8211; Catch errors at compile time, not in production.<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>Modules make applications scalable<\/strong> &#8211; Each feature is isolated and independently testable.<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>Built-in solutions for common problems<\/strong> &#8211; Authentication, validation, error handling, logging, all built-in.<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>Great for teams<\/strong> &#8211; New developers understand the code structure immediately.<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>Enterprise-grade but developer-friendly<\/strong> &#8211; The power of Spring Boot or ASP.NET Core, but with Node.js and JavaScript.<\/p>\n<\/li>\n<\/ol>\n<hr \/>\n<h2 class=\"text-3xl font-semibold mt-14 mb-8 \">Next Steps<\/h2>\n<p class=\" text-lg my-6\">Once you understand NestJS basics:<\/p>\n<ol class=\"list-decimal ml-6 my-6\">\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>Build a complete application<\/strong> &#8211; Users, posts, comments, with authentication<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>Add a database<\/strong> &#8211; PostgreSQL with TypeORM or Prisma<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>Implement authentication<\/strong> &#8211; JWT tokens, refresh tokens<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>Add validation<\/strong> &#8211; Request validation with class-validator<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>Write tests<\/strong> &#8211; Unit tests for services, integration tests for controllers<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>Deploy to production<\/strong> &#8211; Using Caddy and PM2 (from the earlier guide)<\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><strong>Add advanced features<\/strong> &#8211; WebSockets, caching, background jobs<\/p>\n<\/li>\n<\/ol>\n<hr \/>\n<h2 class=\"text-3xl font-semibold mt-14 mb-8 \">Common Misconceptions About NestJS<\/h2>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">&#8220;NestJS is heavyweight&#8221;<\/h3>\n<p class=\" text-lg my-6\"><strong>False.<\/strong> NestJS itself is lightweight. You only pay for what you use. Add features as needed.<\/p>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">&#8220;NestJS is slow&#8221;<\/h3>\n<p class=\" text-lg my-6\"><strong>False.<\/strong> NestJS is built on Express\/Fastify, which are very fast. The framework adds minimal overhead.<\/p>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">&#8220;NestJS is only for large projects&#8221;<\/h3>\n<p class=\" text-lg my-6\"><strong>False.<\/strong> While NestJS shines in large projects, it&#8217;s great for medium and small projects too. The structure helps even with small codebases.<\/p>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">&#8220;I have to use TypeScript with NestJS&#8221;<\/h3>\n<p class=\" text-lg my-6\"><strong>False.<\/strong> You can use plain JavaScript, but TypeScript is strongly recommended for full benefits.<\/p>\n<h3 class=\"text-2xl mt-10 mb-4 font-bold \">&#8220;NestJS ties you to one framework&#8221;<\/h3>\n<p class=\" text-lg my-6\"><strong>False.<\/strong> NestJS works with Express OR Fastify. You can switch with one line of code.<\/p>\n<hr \/>\n<h2 class=\"text-3xl font-semibold mt-14 mb-8 \">Further Reading<\/h2>\n<ul class=\"list-disc ml-6 my-6\">\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><a class=\"! !underline\" href=\"https:\/\/docs.nestjs.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">NestJS Official Documentation<\/a><\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><a class=\"! !underline\" href=\"https:\/\/docs.nestjs.com\/first-steps\" target=\"_blank\" rel=\"noopener noreferrer\">NestJS Tutorial &#8211; Building a REST API<\/a><\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><a class=\"! !underline\" href=\"https:\/\/typeorm.io\/\" target=\"_blank\" rel=\"noopener noreferrer\">TypeORM Documentation<\/a><\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><a class=\"! !underline\" href=\"https:\/\/www.prisma.io\/docs\/\" target=\"_blank\" rel=\"noopener noreferrer\">Prisma Documentation<\/a><\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><a class=\"! !underline\" href=\"https:\/\/docs.nestjs.com\/fundamentals\/testing\" target=\"_blank\" rel=\"noopener noreferrer\">Testing in NestJS<\/a><\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><a class=\"! !underline\" href=\"https:\/\/docs.nestjs.com\/faq\/common-mistakes\" target=\"_blank\" rel=\"noopener noreferrer\">NestJS Best Practices<\/a><\/p>\n<\/li>\n<li class=\" text-lg my-2\">\n<p class=\" text-lg my-6\"><a class=\"! !underline\" href=\"https:\/\/docs.nestjs.com\/microservices\/basics\" target=\"_blank\" rel=\"noopener noreferrer\">Microservices with NestJS<\/a><\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: When Simple Express Scripts Aren&#8217;t Enough You start with a simple Node.js project. A few Express routes, some database calls, maybe authentication. The code works, and you ship it. Then your project grows. Six months later: You have 50 route handlers scattered across 10 files Business logic is mixed everywhere (controllers, middleware, utility functions)&#8230;<\/p>\n","protected":false},"author":1,"featured_media":4748,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[213],"tags":[227,214,218,222],"class_list":["post-4931","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software-development","tag-backend","tag-mern","tag-nodejs","tag-restapi","th-blog blog-single has-post-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.softcolon.com\/blogs\/wp-json\/wp\/v2\/posts\/4931","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.softcolon.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.softcolon.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.softcolon.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.softcolon.com\/blogs\/wp-json\/wp\/v2\/comments?post=4931"}],"version-history":[{"count":2,"href":"https:\/\/www.softcolon.com\/blogs\/wp-json\/wp\/v2\/posts\/4931\/revisions"}],"predecessor-version":[{"id":4934,"href":"https:\/\/www.softcolon.com\/blogs\/wp-json\/wp\/v2\/posts\/4931\/revisions\/4934"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.softcolon.com\/blogs\/wp-json\/wp\/v2\/media\/4748"}],"wp:attachment":[{"href":"https:\/\/www.softcolon.com\/blogs\/wp-json\/wp\/v2\/media?parent=4931"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.softcolon.com\/blogs\/wp-json\/wp\/v2\/categories?post=4931"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.softcolon.com\/blogs\/wp-json\/wp\/v2\/tags?post=4931"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}