DEV Community

Cover image for How I Built a Production Micro-SaaS in Node.js With 0 npm Dependencies
Otteli
Otteli

Posted on

How I Built a Production Micro-SaaS in Node.js With 0 npm Dependencies

Every time I kicked off a small SaaS or paid API, the first weekend disappeared into the same ritual:

  • Installing 600+ npm packages
  • Fighting ORM migration drift
  • Waiting 35 seconds for a bundler to rebuild
  • Paying for a managed Postgres instance before having a single paying user

Modern Node.js (22.5+) quietly changed the rules of the game. Out of the box, Node now ships:

  • node:sqlite — synchronous, fast, embedded SQLite with WAL mode
  • node:crypto — scrypt, timingSafeEqual, HMAC-SHA256, random tokens
  • Native fetch — no massive SDK needed to call Stripe's REST API
  • node:test — built-in test runner with zero config

I wanted to see how far you can push a zero-dependency Node.js backend for a real, monetized Micro-SaaS (auth, Stripe subscriptions, metered API keys, rate limiting, and an admin MRR dashboard).

Here are the 3 core patterns that made it surprisingly clean — and fast (<50ms cold start).


1. Zero-ORM SQLite in WAL Mode (node:sqlite)

With node:sqlite, you don't need native C++ build toolchains or an ORM layer. Enable WAL mode + foreign keys and run idempotent migrations on startup:

import { DatabaseSync } from 'node:sqlite';

const db = new DatabaseSync('./data/app.db');
db.exec('PRAGMA journal_mode = WAL;');
db.exec('PRAGMA synchronous = NORMAL;');
db.exec('PRAGMA foreign_keys = ON;');

db.exec(`
  CREATE TABLE IF NOT EXISTS api_usage (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    user_id INTEGER NOT NULL,
    month TEXT NOT NULL,
    request_count INTEGER NOT NULL DEFAULT 0,
    UNIQUE(user_id, month)
  );
`);

// Atomic monthly quota increment
const incrementUsage = db.prepare(`
  INSERT INTO api_usage (user_id, month, request_count)
  VALUES (?, ?, 1)
  ON CONFLICT(user_id, month) DO UPDATE SET request_count = request_count + 1
`);
Enter fullscreen mode Exit fullscreen mode

On a single $4/mo VPS or a Fly.io persistent volume, WAL-mode SQLite comfortably handles thousands of requests per second with sub-millisecond reads and $0/mo database hosting.


2. Salted scrypt Password Hashing Without bcrypt

You don't need native bcrypt addons either. node:crypto ships scryptSync and timingSafeEqual:

import crypto from 'node:crypto';

export function hashPassword(password) {
  const salt = crypto.randomBytes(16).toString('hex');
  const derived = crypto.scryptSync(password, salt, 64).toString('hex');
  return `${salt}:${derived}`;
}

export function verifyPassword(password, storedHash) {
  const [salt, keyHex] = String(storedHash || '').split(':');
  if (!salt || !keyHex) return false;
  const derived = crypto.scryptSync(password, salt, 64);
  const storedBuf = Buffer.from(keyHex, 'hex');
  return derived.length === storedBuf.length && crypto.timingSafeEqual(derived, storedBuf);
}
Enter fullscreen mode Exit fullscreen mode

Pair this with HttpOnly; SameSite=Lax; Secure session cookies and a per-session CSRF token checked via timingSafeEqual, and your auth layer is rock-solid with zero external dependencies.


3. Verifying Stripe Webhooks Without the Stripe SDK

The Stripe Node SDK is great, but if you only need Checkout Sessions, Billing Portal, and webhook verification, Stripe's REST API is plain form-encoded fetch, and webhook signature verification is ~25 lines of node:crypto:

import crypto from 'node:crypto';

export function verifyStripeWebhookSignature(rawBody, signatureHeader, secret, toleranceSec = 300) {
  if (!signatureHeader || !secret) return false;

  const parts = Object.fromEntries(
    signatureHeader.split(',').map((kv) => kv.split('=').map((s) => s.trim()))
  );
  const timestamp = Number(parts.t);
  if (!Number.isFinite(timestamp)) return false;

  // Reject replay attacks outside the 5-minute window
  if (Math.abs(Math.floor(Date.now() / 1000) - timestamp) > toleranceSec) return false;

  const expected = crypto
    .createHmac('sha256', secret)
    .update(`${timestamp}.${rawBody}`, 'utf8')
    .digest('hex');

  const sigBuf = Buffer.from(parts.v1 || '', 'utf8');
  const expBuf = Buffer.from(expected, 'utf8');
  return sigBuf.length === expBuf.length && crypto.timingSafeEqual(sigBuf, expBuf);
}
Enter fullscreen mode Exit fullscreen mode

Important gotcha: always verify against the raw UTF-8 request body before calling JSON.parse(), and store processed event.id values in a UNIQUE SQLite column so duplicate Stripe retries are safely ignored.


Live Demo & Full Starter Kit

I wrapped all of this — auth, CSRF, rate limiting, Stripe Checkout & webhooks (plus a local demo billing mode), SHA-256 hashed API keys, monthly quota metering, an Admin MRR dashboard, Docker/Fly.io/Render configs, and an end-to-end node --test suite — into a clean starter kit called ShipCore Pro.

Are you already using node:sqlite in production, or still sticking to Postgres/Prisma for small projects? Curious to hear your setup in the comments!

Top comments (0)