NoCache

Preview of Auto Delete Expired Documents in MongoDB with Node.js (TTL Index)

Auto Delete Expired Documents in MongoDB with Node.js (TTL Index)

Cyrus Kao

TTL Indexes in MongoDB are very useful for storing data like logs or user sessions. The document will remove itself after a certain amount of time which is specified by the index. This tutorial will be done in both JavaScript and TypeScript using Node.js with node-mongodb-native, which is the official MongoDB Node.js driver.

Preview of How to Change the Version of TypeScript Compiler in VSCode

How to Change the Version of TypeScript Compiler in VSCode

Cyrus Kao

By default, VSCode uses its own TSC (TypeScript Compiler), which is usually not the latest version of TypeScript. To enable the latest features, we'll need to install TypeScript in our package's dependencies and select the version from node_modules in VSCode (.vscode/settings.json).

Preview of Check If an URL is Internal or External in JavaScript/TypeScript

Check If an URL is Internal or External in JavaScript/TypeScript

Cyrus Kao

Knowing whether a link is internal or external is essential for setting rel in HTML a tag. For an external link, noreferrer noopener nofollow is usually recommended. To test a full URL or relative path in JavaScript/TypeScript, we'll be using the URL constructor. It's available in both browsers and Node.js.

Preview of Build a Telegram Bot to Send Notifications in Node.js with TypeScript

Build a Telegram Bot to Send Notifications in Node.js with TypeScript

Cyrus Kao

Instead of using Telegram bot frameworks like telegraf.js and node-telegram-bot-api, I created a Telegram sender with less than 100 lines of code in Node.js to simply send notifications to myself. And there is nothing wrong with using a full-featured framework, but building your own is definitely easier to maintenance.

Preview of Build a Key-Value LRU Cache Module in Node.js with Typescript

Build a Key-Value LRU Cache Module in Node.js with Typescript

Cyrus Kao

I created a simple key-value LRU (Least Recently Used) cache module for storing user sessions of this blog. And with the power of Javascript ES6 Map object, it's easy to implement a efficient cache system. In this guide we'll be building this module from scratch in Node.js with Typescript.

Preview of Build an IP Based Rate Limiting Module in Node.js with Typescript

Build an IP Based Rate Limiting Module in Node.js with Typescript

Cyrus Kao

I recently wrote a very simple IP address based rate limit module called rt-limit to throttle requests for this blog. Although rate limiting is more commonly done on reverse proxies like Nginx and Apache, being able to manage traffic on your own back-end server is always more flexible.

Preview of Build a Cryptographically-Secure Password Generator in Node.js with TypeScript

Build a Cryptographically-Secure Password Generator in Node.js with TypeScript

Cyrus Kao

I wrote a dead simple JavaScript library called pswd-generator to generate passwords for this blog. In just 23 lines of code, I was able to build a cryptographically-secure password generator thanks to Node.js's native crypto module. And this guide will show you how it's done with TypeScript.

Preview of How to Fix Zalgo Issue (Spamming Console) with Colors.js 1.4.1/1.4.2

How to Fix Zalgo Issue (Spamming Console) with Colors.js 1.4.1/1.4.2

Cyrus Kao

Colors.js, the open source Javascript package used by 4.3 million repositories has recently been corrupted by its owner Marak. Causing the library spamming console with a bunch of garbled characters.