Home

Tìm hiểu & Cài đặt NextJS 14

Next.js là framework React phổ biến nhất hiện nay, được phát triển bởi Vercel. Phiên bản 14 giới thiệu App Router, Server Components, và Server Actions — những tính năng thay đổi cách chúng ta xây dựng ứng dụng web hiện đại. 1. Giới thiệu Next.js 14 nổi bật với: App Router — kiến trúc routing mới dựa trên thư mục app/ React Server Compone...

Read more

NestJS – Upload File với Multer

NestJS tích hợp sẵn Multer thông qua @nestjs/platform-express, giúp xử lý upload file multipart/form-data rất đơn giản mà không cần cài thêm package nào. 1. Cài đặt type definition npm install --save-dev @types/multer 2. Upload một file Controller import { Controller, Post, UseInterceptors, UploadedFile, BadRequestException, } fr...

Read more

NestJS – Guards, Interceptors & Pipes

NestJS có hệ thống request lifecycle rõ ràng với nhiều lớp xử lý: Guard (phân quyền), Interceptor (biến đổi request/response), Pipe (validate & transform). Hiểu rõ ba khái niệm này giúp bạn xây dựng API sạch và nhất quán. 1. Request Lifecycle trong NestJS Request → Middleware → Guards ← Có được phép không? → Interceptors ← Be...

Read more

NestJS – Authentication với JWT

Authentication là tính năng không thể thiếu trong bất kỳ ứng dụng backend nào. Bài này hướng dẫn xây dựng hệ thống đăng nhập với JWT (JSON Web Token) trong NestJS sử dụng @nestjs/passport và @nestjs/jwt. 1. Cài đặt thư viện npm install --save @nestjs/passport @nestjs/jwt passport passport-jwt bcryptjs npm install --save-dev @types/passport-jwt...

Read more

NestJS – CRUD với MongoDB (Mongoose)

Trong bài này, chúng ta sẽ xây dựng một API CRUD hoàn chỉnh với NestJS và MongoDB thông qua thư viện Mongoose. Đây là bộ đôi rất phổ biến trong thực tế. 1. Chuẩn bị Bạn cần có project NestJS đã khởi tạo. Nếu chưa có, hãy xem bài Tìm hiểu & Cài đặt NestJS. Cài đặt Mongoose cho NestJS: npm install --save @nestjs/mongoose mongoose 2. Kết ...

Read more

NestJS – CRUD với TypeORM & MySQL

TypeORM là ORM phổ biến nhất trong hệ sinh thái NestJS, hỗ trợ MySQL, PostgreSQL, SQLite và nhiều database khác. Bài này hướng dẫn xây dựng CRUD API hoàn chỉnh với NestJS + TypeORM + MySQL. 1. Cài đặt npm install --save @nestjs/typeorm typeorm mysql2 2. Cấu hình kết nối // app.module.ts import { TypeOrmModule } from '@nestjs/typeorm'; @Mod...

Read more