Native C++ Reimplementation of node:crypto, node:buffer, and node:fs
- Last updated
- Prerequisites:
- Node.js core modules (`node:crypto`, `node:buffer`, `node:fs`)
- bun
- node-compat
- crypto
- buffer
- fs
- boringssl
- zig
Read at your depth
The practical view
Bun provides a built-in compatibility layer for Node.js core modules (`node:fs`, `node:crypto`, `node:buffer`, `node:path`, `node:http`, `node:events`, `node:child_process`). You can import them directly (`import crypto from 'node:crypto'`) or run existing npm packages (like Express, Prisma, Next.js, Lodash) with near 100% compatibility.
The same idea in other frameworks
Original Node.js C++ and JS core module implementations.Deno `std/node` compatibility layer.Native Zig/C++ BoringSSL reimplementation of Node core modules.Browserify / webpack polyfills.Legacy vs modern
Node.js Core Module Compatibility
Existing Node.js code runs unmodified in Bun, utilizing fast native BoringSSL crypto and SIMD buffers.
const crypto = require('node:crypto'); const hash = crypto.createHash('sha256').update(data).digest('hex');import crypto from 'node:crypto'; // ✅ NEW: Executes 2-3x faster via native BoringSSLInterview gotchas
Context
Interviewers test your knowledge of underlying native dependencies in modern runtimes.
The mechanical answer
Node.js uses **OpenSSL**. Bun uses **BoringSSL** (Google's lightweight, high-performance fork of OpenSSL used in Chromium and Android). BoringSSL reduces binary footprint and contains optimized assembly for modern x86-64 and ARM64 cryptographic operations.
Trap
Some legacy, deprecated cryptographic algorithms (like outdated SSLv3 ciphers or obscure DES modes) are intentionally removed in BoringSSL and therefore unsupported in Bun.
Context
Checks practical enterprise framework compatibility.
The mechanical answer
Yes. Express.js, Fastify, and NestJS run directly on Bun using Bun's `node:http` and `node:net` compatibility layer without modifications. However, using native `Bun.serve()` is 2-4x faster than running Express over the `node:http` compatibility layer.
Trap
While Express runs on Bun, running it on Bun still incurs the overhead of Express's middleware design; for maximum performance, migrate to `Bun.serve` or Elysia/Hono.