Posts

Showing posts with the label validation

Using TypeORM in a NestJS Project

Image
Introduction TypeORM is a powerful ORM (Object-Relational Mapper) library for the Node.js ecosystem, written in TypeScript. It allows developers to interact with databases using classes and objects instead of writing complex raw SQL queries. Key Advantages Excellent TypeScript support: Fully leverages decorators and type-checking, helping detect errors during development instead of at runtime. Supports multiple databases: Compatible with popular database management systems such as MySQL, PostgreSQL, SQLite, etc. Flexible patterns (Data Mapper & Active Record): Lets you choose the appropriate implementation style depending on project size (Data Mapper for large, complex projects; Active Record for smaller, quick projects). Migration management: Provides powerful tools to manage database schema changes systematically, helping synchronize changes across development teams. Query Builder: In addition to object-based operations, TypeORM provides a Query Builder for constructing complex q...

Enhance Security for NodeJS Application

Image
1. Limiting the number of requests Limiting the number of requests (from a single IP address within a specific timeframe) is a method used to prevent denial-of-service ( DOS, DDOS ) attacks or brute force attacks that could overload your server. If you're using Express , integrating this is quite straightforward using the express-rate-limit  package. import * as express from 'express' import helmet from 'helmet' import expressRateLimit from 'express-rate-limit' const app = express () const limiter = expressRateLimit ({ windowMs: 10 * 60 * 1000 , // ms, ~10 minutes max: 50 , // limit each IP to 50 requests }) const specificLimiter = expressRateLimit ({ windowMs: 60 * 60 * 1000 , // 1 hour window max: 2 , // start blocking after 2 requests message: 'Too many requests' , // default 429 TOO MANY REQUESTS }) app . use ( limiter ) // use for all route . use ( '/common' , ( req , res ) => { res . json ...