NestJS Logo

Node.js backend tutorials

Step-by-step tutorials that build complete Node.js backends in TypeScript with NestJS: REST APIs, e-commerce, SaaS, chat, bookings, payments and AI.

Each tutorial builds one application of the kind teams actually ship, from an empty project to code you could deploy, and links to the chapters of this documentation for the details of each part. They use the current APIs: validation with Zod schemas, the Node adapter, @nestjs/authentication, and Drizzle on PostgreSQL. Every listing comes from an application that was built and tested, and every output on the pages comes from running it.

Most of a backend is ordinary CRUD, so the tutorials spend their time on the parts that aren't: what happens when two requests arrive at once, when a client retries, or when a token is stolen. Each one tests those guarantees against PostgreSQL.

Where to start#

Start with Build a REST API with JWT authentication in Node.js. It begins with a single file, and adds request validation, a PostgreSQL database, sign-up with access and refresh tokens, rate limiting, security headers, an OpenAPI document, health checks, JSON logs and end-to-end tests.

The other tutorials start from its finished application, and add what their task needs. Accept payments with webhooks continues the e-commerce backend instead.

The tutorials#

TutorialWhat you buildThe hard part it solves
REST API with JWT authenticationA notes API with sign-up, access and refresh tokens, PostgreSQL, OpenAPI, health checks and testsRefresh-token reuse, sign-in timing that reveals accounts, writes that race
E-commerce backendA catalog that only staff edit, carts, checkout, cancelling and shippingNever selling more than is in stock, however many customers check out at once
Multi-tenant SaaS backendOrganizations, roles, email invitations, tenant-owned projects, an audit logKeeping every query inside its tenant, and never losing an organization's last owner
Project-management APIProjects, tasks and comments, live updates over Server-Sent Events, due-date remindersPermissions checked record by record, and status changes that don't overwrite each other
Real-time chat backendA WebSocket gateway with rooms, message history, presence and typing indicatorsAuthenticating sockets, and checking membership on every message
Booking systemBookable resources, free slots per day, bookings and cancellationsNo double bookings, guaranteed by the database
Emails and background jobsA welcome email and a daily digest, sent from a BullMQ queueEmails that are never lost or sent twice, and scheduled jobs that run on one instance
File upload serviceUploads, downloads, expiring links and per-user quotas, on disk or S3Checking type and size while streaming, and quotas under concurrent uploads
Payments with webhooksPayments for the e-commerce backend, confirmed by the provider's signed webhooksApplying each payment event exactly once, in any order
AI chat backendA chatbot over the user's notes, with tools and answers streamed to the browserTools that see only the user's own data, and stopping the model when the browser goes away

What you need#

  • Node.js 22 or later, and the Nest CLI.
  • Docker, to run PostgreSQL locally, and Redis for the background jobs tutorial.
  • curl, to try the endpoints. Each tutorial also serves its OpenAPI document with Swagger UI.

The AI chat tutorial runs without a model provider's API key: it uses a scripted model, and shows the configuration for a real one.

More#

Edit on GitHub

Support us

Nest is an MIT-licensed open source project. It can grow thanks to the support of these awesome people. If you'd like to join them, please read more here.

Principal Sponsors

SerpApi LogoTrilon LogoMojam Logo

Sponsors / Partners

Become a sponsor