Skip to content

Instantly share code, notes, and snippets.

View mostafa8026's full-sized avatar
🎯
Focusing

Mostafa mostafa8026

🎯
Focusing
View GitHub Profile

Standalone applications

There are several ways of mounting a Nest application. You can create a web app, a microservice or just a bare Nest standalone application (without any network listeners). The Nest standalone application is a wrapper around the Nest IoC container, which holds all instantiated classes. We can obtain a reference to any existing instance from within any imported module directly using the standalone application object. Thus, you can take advantage of the Nest framework anywhere, including, for example, scripted CRON jobs. You can even build a CLI on top of it.

Getting started

To create a Nest standalone application, use the following construction:

@@filename()
@mostafa8026
mostafa8026 / window-counter.ts
Last active May 20, 2023 09:48
A TypeScript class for tracking the number of requests within a sliding time window
class WindowCounter {
private windowSize: number; // Window size in seconds
private counter: Map<number, number>; // Map to store request counts
private timer: any; // Timer reference
constructor(windowSize: number) {
this.windowSize = windowSize;
this.counter = new Map();
this.timer = null;
}
@mostafa8026
mostafa8026 / README.md
Created May 24, 2023 18:02 — forked from anchan828/README.md
This is an improvement to allow @nestjs/typeorm@8.1.x to handle CustomRepository. I won't explain it specifically, but it will help in some way. https://github.com/nestjs/typeorm/pull/1233

You need to provide some classes and decorators yourself to maintain the same style as typeorm@2.x.

1. EntityRepository -> CustomRepository

@EntityRepository(UserEntity)
export class UserRepository extends Repository<UserEntity> {}

import got, { HTTPError, Method, Options } from "got/dist/source";
import * as fs from "fs";
import FormData from "form-data";
const gotExtended = got.extend({
hooks: {
beforeRetry: [
(options, error, retryCount) => {
console.log("beforeRetry", retryCount);
},