export const Customer = Type.Object({
firstName: Type.String(),
lastName: Type.String(),
age: Type.Number(),
dob: Type.Date(),
address: Type.Object({
streetAddress: Type.String(),
city: Type.String(),
import { performance } from 'perf_hooks' | |
export type Timer = ReturnType<typeof createTimer> | |
/** | |
* High resolution timer. Note that Number.MAX_SAFE_INTEGER | |
* limits the total duration to ~104 hours. | |
*/ | |
export const createTimer = () => { | |
const times: number[] = [] |
/* eslint-disable @typescript-eslint/no-misused-promises */ | |
import { Readable, Transform, Writable } from 'node:stream' | |
import { pipeline } from 'node:stream/promises' | |
export const asyncHandler = (handle: (value: any) => Promise<void>) => { | |
return new Writable({ | |
objectMode: true, | |
write: async (value, _, next) => { | |
try { | |
await handle(value) |
These launch configs will allow you to debug typescript files directly from VSCode. It will honor the tsconfig
and resolve node modules properly. You do not need to install ts-node
or nodemon
, as everything is run using npx
. The first
{
"configurations": [
{
"type": "node",
"request": "launch",
Here, I am going to examine NestJS -- primarily focusing on its dependency injection --
Nest's DI system is based on a custom-defined module system. For every service defined in the application, there is a module file that "owns" that service. I use the term "service" loosely here to simply mean "anything we want to be part of the DI system". For example:
@Injectable()
Originally introduced by yarn
, starting with version 7 npm
also provides support for this.
Workspaces are first-class support in the package manager for monorepo structures in npm packages. A monorepo is simply a collection of related packages, and having them share a single git repo can help eliminate a lot of redundancy in the project setup, as well as make it easier to work with interdependencies during development.
They're relatively simple. They consist of:
- a parent directory whose
package.json
contains a list (or wildcard pattern) defining subprojects
type Semaphore = { | |
acquire: () => Promise<void>; | |
release: () => void; | |
}; | |
export const simpleSemaphore = (size: number): Semaphore => { | |
const waiting: (() => void)[] = []; | |
let available = size; | |
const acquire = async (): Promise<void> => { |
#!/usr/bin/env node | |
const { exec } = require('child_process'); | |
const { resolve } = require('path'); | |
const cwd = process.argv[2] ? resolve(process.argv[2]) : process.cwd(); | |
const maxBuffer = 10 * 1024 * 1024; | |
const execShell = (command) => { | |
return new Promise((resolve) => { | |
exec(command, { cwd, maxBuffer }, (error, stdout, stderr) => { |