惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
A
Arctic Wolf
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Proofpoint News Feed
S
Schneier on Security
The Cloudflare Blog
Security Latest
Security Latest
S
SegmentFault 最新的问题
L
Lohrmann on Cybersecurity
T
Tailwind CSS Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cyber Attacks, Cyber Crime and Cyber Security
K
Kaspersky official blog
Latest news
Latest news
月光博客
月光博客
aimingoo的专栏
aimingoo的专栏
P
Privacy & Cybersecurity Law Blog
F
Fortinet All Blogs
C
Cybersecurity and Infrastructure Security Agency CISA
美团技术团队
博客园 - 叶小钗
H
Help Net Security
博客园 - 【当耐特】
云风的 BLOG
云风的 BLOG
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
A
About on SuperTechFans
WordPress大学
WordPress大学
Cloudbric
Cloudbric
IT之家
IT之家
Last Week in AI
Last Week in AI
S
Securelist
Google Online Security Blog
Google Online Security Blog
J
Java Code Geeks
Microsoft Azure Blog
Microsoft Azure Blog
L
LINUX DO - 最新话题
Know Your Adversary
Know Your Adversary
爱范儿
爱范儿
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
G
Google Developers Blog
C
CERT Recently Published Vulnerability Notes
宝玉的分享
宝玉的分享
博客园 - Franky
TaoSecurity Blog
TaoSecurity Blog
P
Proofpoint News Feed
大猫的无限游戏
大猫的无限游戏
Jina AI
Jina AI
L
LINUX DO - 热门话题
N
News and Events Feed by Topic
B
Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Production Ready NestJS Microservice Setup with Candy-Nest-CLI 🍬
Ashish Kushw · 2026-05-19 · via DEV Community

If you build microservices with NestJS, you already know how powerful and structured the framework is. However, starting a new project often involves a fair amount of initial setup.

Every time a new service is spun up, developers usually have to go through similar steps:

  • Setting up docker-compose.yml for local databases.
  • Configuring TypeORM, Prisma, or Mongoose.
  • Wiring up message brokers like Kafka or RabbitMQ.
  • Dealing with local environment startup issues.
  • Setting up loggers and metrics.

By the time you actually start writing business logic, a good amount of time has already gone into scaffolding.

Save your AI tokens! While you could prompt ChatGPT or Claude to write this boilerplate, generating a fully-wired NestJS microservice with infrastructure configs easily burns 3,000 to 5,000+ tokens per project (not to mention the context window eaten up by debugging configuration errors). Candy-Nest-CLI lets you bypass that entirely so you can save your usage limits for writing actual business logic.

To help automate this process, I put together Candy-Nest-CLI—an open-source interactive scaffolding tool designed to generate production-ready NestJS microservices.


🛠️ Building a Service: Step-by-Step

Let's walk through exactly how easy it is to spin up a fully-wired backend service with a PostgreSQL database and Kafka messaging queue.

Step 1: Installation & Initialization

You can either install the CLI globally to have it available anywhere, or run it directly on the fly.

Option 1: Global Installation (Recommended)
Open your terminal and install the package globally:

# Using npm
npm install -g candy-nest-cli

# Or using yarn
yarn global add candy-nest-cli

Enter fullscreen mode Exit fullscreen mode

Once installed, you can generate a new project by running:

candy-nest-cli init user-service

Enter fullscreen mode Exit fullscreen mode

Option 2: Using npx (No Installation)
If you prefer not to install packages globally, you can just run:

npx candy-nest-cli init user-service

Enter fullscreen mode Exit fullscreen mode

Step 2: Choose Your Stack

The CLI uses @inquirer/prompts to walk you through a highly detailed setup. To build our target microservice, we will answer the prompts like this:

  1. What is the name of your project? user-service
  2. Which package manager do you want to use? npm
  3. Select the communication protocols to support: REST
  4. Which HTTP adapter do you want to use? Express
  5. Do you want to include a database? Yes
  6. Select databases to include: PostgreSQL (RDBMS)
  7. Which ORM for PostgreSQL? TypeORM
  8. Do you want to configure an messaging queue? Yes
  9. Which messaging queue do you want to use? Kafka
  10. Do you want to configure Dead Letter Queue (DLQ) and Retries? Yes
  11. Do you want to include Redis for caching? Yes
  12. Which logger do you want to configure? Pino
  13. Which tracing & metrics solution do you want? Prometheus
  14. Do you want to generate API documentation (Swagger)? Yes
  15. Do you want to include a Circuit Breaker (Opossum)? Yes

1. Package Manager Selection

Choose your preferred package manager (npm, yarn, or pnpm). We will select npm for this project.

Package Manager Selection

2. Protocol Selection

Select the communication protocols your microservice will support. The CLI supports a multi-protocol combination of REST, GraphQL, gRPC, and WebSockets. We'll go with REST for standard HTTP routing.

Protocol Selection

3. HTTP Adapter Selection

Choose between Express (the industry standard) and Fastify (high performance). We'll select Express for maximum compatibility.

Adapter Selection

4. Database Integration

Select whether you want to include a database module. We will select Yes to set up persistence.

Database Option Selection

5. Database Choice Selection

Choose which database to use (PostgreSQL, MySQL, or MongoDB). We'll select PostgreSQL (RDBMS) for robust relational database management.

Database Choice Selection

6. Database ORM Selection

Select your ORM of choice. The CLI supports TypeORM or Prisma for SQL databases. Let's select TypeORM.

ORM Selection

7. Messaging Queue Integration

Select whether you want to configure an event-driven messaging queue. We'll select Yes.

Queue Option Selection

8. Queue Choice Selection

Choose between Kafka, RabbitMQ, and BullMQ as your message broker. We'll select Kafka to build an event-driven stream processing microservice.

Queue Choice Selection

9. Dead Letter Queue (DLQ) & Retries

Select whether to set up robust message handling with a Dead Letter Queue (DLQ) and custom retry loops to ensure event resiliency out of the box. We'll select Yes.

DLQ Prompt Selection

10. Redis Caching

Choose whether to set up Redis as a fast, in-memory distributed cache. We'll select Yes.

Redis Prompt Selection

11. Logger Selection

Select your logging solution (Winston, Pino, or the default NestJS logger). We'll select Pino for high-speed JSON logging.

Logger Selection

12. Observability & Tracing

Select your observability stack (Prometheus or OpenTelemetry). We will configure Prometheus metrics.

Observability Selection

13. API Documentation

Choose if you want fully-featured auto-generating Swagger documentation for your REST APIs. We'll select Yes.

Swagger Prompt Selection

14. Circuit Breaker

Enable Opossum-based Circuit Breakers to guard your outgoing HTTP requests and RPC calls from downstream failures. We'll select Yes.

Circuit Breaker Prompt Selection

After confirming your final choice, the CLI will output the progress as it generates the files, writes configurations, and installs the dependencies automatically.

Generation Progress

Scaffolding Complete

Sensible Defaults vs. Ultimate Flexibility

candy-nest-cli is designed with sensible defaults, allowing you to breeze through by just pressing Enter. In our guide, we only customized a few options (like choosing Pino for faster logging and enabling Dead Letter Queues for Kafka).

Here is how our choices compare against the CLI's default settings and alternative integrations:

Option Selected in Walkthrough Default Preset Alternative Choices
Package Manager npm npm yarn, pnpm
Protocols REST [REST] GraphQL, gRPC, WebSockets
HTTP Adapter Express Express Fastify
Database PostgreSQL (RDBMS) PostgreSQL MySQL, MongoDB
SQL ORM TypeORM TypeORM Prisma
Messaging Queue Kafka Kafka RabbitMQ, BullMQ
DLQ & Retries Yes (Customized) No No
Redis Caching Yes Yes No
Logger Pino (Customized) Winston Winston, None
Observability Prometheus Prometheus OpenTelemetry, None
Swagger API Docs Yes Yes No
Circuit Breaker Yes Yes No

Step 3: Boot Up the Infrastructure

Once the CLI finishes generating the code, all your infrastructure is ready to go. No writing Docker files from scratch.

cd user-service
cp .env.example .env
docker-compose up -d
npm run start:dev

Enter fullscreen mode Exit fullscreen mode

Because of how the CLI scaffolds the project, Kafka boots in KRaft mode with a special initialization container. You will see Postgres, Redis, and Kafka all start up perfectly without any race conditions.

Docker Compose Up

Step 4: Run the App

With our infrastructure running, we just start the NestJS app:

npm run start:dev

Enter fullscreen mode Exit fullscreen mode

NestJS Startup Logs

Just like that, you have a production-ready microservice running in under 2 minutes.

Note: you might get kafka-topic related error at startup, you can simply restart the application after a few seconds, and topic will be created or you can exec into docker and create the topic manually.

🌐 Interactive Developer Playgrounds

If you enabled Swagger API Docs or GraphQL, the CLI pre-configures and exposes rich, interactive playgrounds out of the box so you can immediately execute and test operations:

Swagger API Playground (REST)

Access the auto-generated Swagger UI at http://localhost:3000/api/docs to see your REST endpoints, database CRUD examples, and health checks beautifully laid out:

Swagger API Documentation

Apollo Sandbox Playground (GraphQL)

If you enabled GraphQL, open http://localhost:3000/graphql to view the Apollo Sandbox where you can run queries, check schemas, and test mutations immediately:

Apollo GraphQL Sandbox


🏗️ What Exactly Gets Generated?

candy-nest-cli dynamically generates only the modules you asked for.

Here is a look at the generated project structure for the service we just built:

Generated Project Structure

user-service/
├── dist/
├── logs/
├── node_modules/
├── src/
│   ├── database/           # Database configuration and connection module
│   ├── examples/           # REST CRUD database examples
│   ├── graphql/            # GraphQL resolvers and schema setup
│   ├── grpc/               # gRPC controller and service implementations
│   ├── health/             # Terminus-based health indicators
│   ├── kafka/              # Kafka microservice controller and providers
│   ├── logger/             # Pino/Winston logging configurations
│   ├── redis/              # Redis caching module and service
│   ├── resiliency/         # Circuit Breaker (Opossum) configuration
│   ├── websockets/         # WebSockets gateway and adapter
│   ├── app.controller.spec.ts
│   ├── app.controller.ts
│   ├── app.module.ts
│   ├── app.service.ts
│   ├── app.throttler.guard.ts # Robust cross-protocol rate limiting guard
│   ├── main.ts             # Microservice hybrid bootstrapper (HTTP, gRPC, Kafka)
│   └── schema.gql          # Auto-generated GraphQL schema
├── test/                   # E2E test suites
├── .env
├── .env.example
├── .prettierrc
├── docker-compose.yml      # Local dev stack (PostgreSQL, Kafka, Redis)
├── Dockerfile              # Multi-stage production build definition
├── eslint.config.mjs
├── nest-cli.json
├── package-lock.json
├── package.json
├── README.md
├── tsconfig.build.json
└── tsconfig.json

Enter fullscreen mode Exit fullscreen mode

Fully Wired Code Modules

  • Databases: It generates database.module.ts, injects the ConfigService, and creates a sample Entity or Schema.
  • Message Brokers: It scaffolds the microservice transport layer, including client publishers and controller decorators to consume events.
  • Testing Suite: Fully-mocked unit tests (.spec.ts) are generated for every selected module (including database services, Kafka producers/consumers, Pino loggers, and Redis). It even includes a dedicated regression E2E test file (regression.e2e-spec.ts) so you can run npm run test out of the box!
  • API Documentation: Because we selected REST, Swagger is automatically hooked up to main.ts!

🚀 Quick Start / Cheatsheet

Start a new interactive project:

npx candy-nest-cli init my-awesome-microservice

Enter fullscreen mode Exit fullscreen mode

Skip the prompts and generate everything (Kitchen Sink mode):

npx candy-nest-cli init my-kitchen-sink-service --all

Enter fullscreen mode Exit fullscreen mode

Add a new feature to an existing CLI-generated project:

npx candy-nest-cli add

Enter fullscreen mode Exit fullscreen mode

Why Candy-Nest-CLI?

The NestJS ecosystem is fantastic, but maintaining consistency across a large microservice architecture can sometimes be challenging.

The goal of this CLI is to provide a standardized, fast way to boot up services that follow common best practices from day one.

If you work with NestJS, feel free to give it a try. I am actively maintaining it and always open to feedback or contributions!

Let me know what you think in the comments below. Happy coding! 🚀