
Node
Apply Node.js `node:test` patterns for HTTP servers, health checks, and graceful shutdown so solo builders ship reliable APIs.
Install
npx skills add https://github.com/ilteoood/harness --skill nodeWhat is this skill?
- Uses native `node:test` with `node:assert/strict`—no extra test runner required
- HTTP server fixture with random port via `listen(0)`
- Health route returns 200 healthy vs 503 shutting_down when `isShuttingDown` is set
- Sets `Connection: close` while draining during shutdown
- `before`/`after` hooks for server start and clean `server.close()`
Adoption & trust: 1 installs on skills.sh; 2 GitHub stars; 3/3 security scanners passed (skills.sh audits); trending (+100% hot-view momentum).
Recommended Skills
Journey fit
Canonical shelf is Ship/testing because the artifact is executable test code validating runtime behavior before release, even though the same patterns help during backend implementation. Testing subphase captures health endpoint assertions, 503 during shutdown, and server lifecycle hooks—exactly what you verify pre-deploy.
Common Questions / FAQ
Is Node safe to install?
skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.
SKILL.md
READMESKILL.md - Node
import { describe, it, before, after } from 'node:test'; import assert from 'node:assert/strict'; import { createServer, IncomingMessage, ServerResponse, Server } from 'node:http'; describe('graceful server shutdown', () => { let server: Server; let isShuttingDown = false; function createHandler() { return (req: IncomingMessage, res: ServerResponse) => { if (isShuttingDown) { res.setHeader('Connection', 'close'); } if (req.url === '/health') { if (isShuttingDown) { res.writeHead(503, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ status: 'shutting_down' })); return; } res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ status: 'healthy' })); return; } res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ message: 'Hello, World!' })); }; } before(() => { server = createServer(createHandler()); server.listen(0); // Random available port }); after(async () => { await new Promise<void>((resolve) => server.close(() => resolve())); }); function getPort(): number { const address = server.address(); if (typeof address === 'object' && address !== null) { return address.port; } throw new Error('Server not listening'); } it('should return healthy status when not shutting down', async () => { const port = getPort(); const response = await fetch(`http://localhost:${port}/health`); assert.equal(response.status, 200); const body = await response.json(); assert.deepEqual(body, { status: 'healthy' }); }); it('should return 503 and shutting_down status during shutdown', async () => { isShuttingDown = true; const port = getPort(); const response = await fetch(`http://localhost:${port}/health`); assert.equal(response.status, 503); const body = await response.json(); assert.deepEqual(body, { status: 'shutting_down' }); isShuttingDown = false; // Reset for other tests }); it('should set Connection: close header during shutdown', async () => { isShuttingDown = true; const port = getPort(); const response = await fetch(`http://localhost:${port}/`); assert.equal(response.headers.get('connection'), 'close'); isShuttingDown = false; }); it('should not set Connection: close header when not shutting down', async () => { const port = getPort(); const response = await fetch(`http://localhost:${port}/`); assert.notEqual(response.headers.get('connection'), 'close'); }); }); import { createServer, IncomingMessage, ServerResponse, Server } from 'node:http'; import closeWithGrace from 'close-with-grace'; /** * Example of a graceful HTTP server using close-with-grace. * Demonstrates proper shutdown handling without connection tracking. */ let isShuttingDown = false; function createHandler() { return (req: IncomingMessage, res: ServerResponse) => { // During shutdown, disable keep-alive to drain connections if (isShuttingDown) { res.setHeader('Connection', 'close'); } // Health check endpoint if (req.url === '/health') { if (isShuttingDown) { res.writeHead(503, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ status: 'shutting_down' })); return; } res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ status: 'healthy' })); return; } // Default response res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ message: 'Hello, World!' })); }; } function closeServer(server: Server): Promise<void> { return new Promise((resolve, reject) => { // Close idle connections immediately server.closeIdleConnections(); server.close((err) => { if (err && err.message !== 'Server is not running') { rej