Skip to main content

Command Palette

Search for a command to run...

How to Connect Nest.js App: Set up Swagger

Published
1 min read
How to Connect Nest.js App: Set up Swagger
M

A self-motivated and enthusiastic web developer with a deep interest in JavaScript (React.js). To work in the Software industry with modern web technologies of different local & multinational Software/ IT agencies of Bangladesh and grow rapidly with increasing responsibilities.

Swagger is a tool to document your API using the OpenAPI specification. Nest has a dedicated module for Swagger, which you will be using shortly.

Get started by installing the required dependencies:

npm install --save @nestjs/swagger swagger-ui-express

Now open main.ts and initialize Swagger using the SwaggerModule class.

  • Solution

      // src/main.ts
    
      import { NestFactory } from '@nestjs/core';
      import { AppModule } from './app.module';
      import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
    
      async function bootstrap() {
        const app = await NestFactory.create(AppModule);
    
        const config = new DocumentBuilder()
          .setTitle('Median')
          .setDescription('The Median API description')
          .setVersion('0.1')
          .build();
    
        const document = SwaggerModule.createDocument(app, config);
        SwaggerModule.setup('api', app, document);
    
        await app.listen(3000);
      }
      bootstrap();
    

While the application is running, open your browser and navigate to http://localhost:3000/api. You should see the Swagger UI.

More from this blog

DSA মানে শুধু LeetCode না — DSA মানে Production System slow না করা

অনেকেই বলে — “ভাই, Web Development-এ DSA লাগে না” আসলে Junior Developer থাকলে এমনটাই মনে হয়।আমি নিজেও Junior থাকতে তাই ভাবতাম। আমার আবার একটা বাজে স্বভাব আছে 😅👉 কোন কিছুর বাস্তব প্রয়োজন না বুঝলে সেটা আমার মাথায় ঢুকে না। Junior থাকতে DSA শিখেছি...

Dec 24, 20253 min read
DSA মানে শুধু LeetCode না — DSA মানে Production System slow না করা

🦀 Rust-এ মেমরি ম্যানেজমেন্ট: GC ছাড়া In-depth.

Rust-এ Garbage Collector (GC) নেই, কিন্তু মেমরি নিরাপত্তা (memory safety) আর performance Rust-এর সবচেয়ে শক্তিশালী দিক।তাই, Go-এর মতো runtime-based GC না থাকা সত্ত্বেও Rust compile-time এ মেমরি ম্যানেজ করে Ownership System, Borrow Checker, আর Lifetime...

Oct 5, 202523 min read
🦀 Rust-এ মেমরি ম্যানেজমেন্ট: GC ছাড়া In-depth.

Morshedul Munna

45 posts

As a Software Developer, I am like an architect who designs and builds digital Products. I use my knowledge and expertise to create modern applications that are both efficient and elegant.