Projects#
TypeScript projects build when the surface is big enough that types are cheaper than tests, or when shipping to a team that will read the code on call.
Typed CLI tool#
A small CLI built with commander and strict typing. The
operator runs it against a list of targets and pipes the JSON
output downstream.
// src/cli.ts
import { Command } from "commander";
import { resolve } from "node:dns/promises";
interface Result { host: string; addrs: string[]; }
const program = new Command()
.name("op-resolve")
.argument("<file>", "one hostname per line")
.option("-c, --concurrency <n>", "parallel queries", (v) => parseInt(v, 10), 50)
.action(async (file: string, opts: { concurrency: number }) => {
const fs = await import("node:fs/promises");
const hosts = (await fs.readFile(file, "utf8"))
.split("\n").map(h => h.trim()).filter(Boolean);
const results: Result[] = [];
for (const h of hosts) {
try {
results.push({ host: h, addrs: await resolve(h) });
} catch {
results.push({ host: h, addrs: [] });
}
}
console.log(JSON.stringify(results, null, 2));
});
program.parse();
HTTP server#
A typed Fastify service run as a small backend for their tooling.
// src/server.ts
import Fastify from "fastify";
interface Target { host: string; port: number; }
const app = Fastify({ logger: true });
app.post<{ Body: Target }>("/scan", async (req, reply) => {
const { host, port } = req.body;
// ...spawn scanner...
return { host, port, scanned_at: Date.now() };
});
app.listen({ host: "0.0.0.0", port: 9000 });
Parser library#
A typed library that parses an operator-relevant format (syslog, JSON-Lines, custom protocol). The library ships type declarations so its callers get full IDE support.
// src/parser.ts
export interface SyslogEntry {
pri: number;
timestamp: Date;
host: string;
program: string;
msg: string;
}
const RFC3164 = /^<(\d+)>(\w{3} +\d+ \d{2}:\d{2}:\d{2}) (\S+) (\S+?):? (.*)$/;
export function parseSyslog(line: string): SyslogEntry | null {
const m = RFC3164.exec(line);
if (!m) return null;
return {
pri: parseInt(m[1], 10),
timestamp: new Date(`${new Date().getFullYear()} ${m[2]}`),
host: m[3],
program: m[4],
msg: m[5],
};
}
References#
Setup for the toolchain.
Frameworks for Fastify, NestJS, Hono, etc.
Projects for the JavaScript-side project ideas (browser extensions, headless scrapers, Node services).
tsup, the zero-config TypeScript bundler.