Logo

Bun & Deno: modern JavaScript runtimes

Bun & Deno: modern JavaScript runtimes

Two Node.js alternatives: **Bun** (fast, Node-compatible, written in Zig) and **Deno** (secure-by-default, native TypeScript, written in Rust). Learn when to use them and how to deploy.

Introduction

Node.js dominates, but two serious challengers emerged:

  • Bun: 3x faster than Node, Node-API compatible, runtime + package manager + bundler + test runner. Written in Zig.
  • Deno: secure-by-default (explicit permissions), native TypeScript, ESM only, written in Rust. Created by Node's original creator.

Prerequisites

  • Linux VPS Debian / Ubuntu
  • Root access

Part 1: Bun

Step 1: Install Bun

curl -fsSL https://bun.sh/install | bash
source ~/.bashrc
bun --version

Or via npm:

npm install -g bun

Step 2: Start an app

bun init myapp
cd myapp

index.ts:

const server = Bun.serve({
  port: 3000,
  fetch(req) {
    return new Response("Hello from Bun!");
  },
});
console.log(`Listening on ${server.port}`);
bun run index.ts

Step 3: Node compatibility

cd my-node-app
bun install     # 10-30x faster than npm install
bun run start

Reads package.json, supports require, ESM, JSON imports, native fetch.

Step 4: Bun as package manager

bun install
bun add express
bun add -d typescript
bun remove express
bun update

Generates bun.lockb (binary lockfile).

Step 5: Bun bundler

bun build ./src/index.ts --outdir ./dist --minify

Bundles ES modules + JSX + TypeScript in one command.

Step 6: Tests with Bun

// test/sum.test.ts
import { expect, test } from "bun:test";

test("add", () => {
  expect(1 + 1).toBe(2);
});
bun test

Built-in test runner, Jest-compatible API.

Step 7: Bun in production

Systemd:

sudo nano /etc/systemd/system/myapp.service
[Unit]
Description=My Bun app
After=network.target

[Service]
Type=simple
User=www-data
WorkingDirectory=/var/www/myapp
ExecStart=/root/.bun/bin/bun run index.ts
Restart=on-failure
Environment=NODE_ENV=production

[Install]
WantedBy=multi-user.target
sudo systemctl enable --now myapp

Or with PM2:

pm2 start "bun run index.ts" --name myapp

Part 2: Deno

Step 1: Install Deno

curl -fsSL https://deno.land/install.sh | sh
source ~/.bashrc
deno --version

Step 2: Deno Hello World

// server.ts
Deno.serve({ port: 3000 }, (req) => {
  return new Response("Hello from Deno!");
});
deno run --allow-net server.ts

Note --allow-net: Deno is secure-by-default.

Step 3: Deno permissions

deno run --allow-net=:3000 server.ts          # only port 3000
deno run --allow-read=./data server.ts        # read folder
deno run --allow-write=./logs server.ts       # write folder
deno run --allow-env=NODE_ENV server.ts       # env vars
deno run -A server.ts                         # all (avoid in prod)

Step 4: Imports

No node_modules! Imports via URL:

import { serve } from "https://deno.land/[email protected]/http/server.ts";
import express from "npm:[email protected]";

Imports cached locally after first download. Reproducible with deno.lock.

Step 5: Tasks (deno.json)

{
  "tasks": {
    "start": "deno run --allow-net --allow-env server.ts",
    "dev": "deno run --watch --allow-net --allow-env server.ts",
    "test": "deno test"
  }
}
deno task start

Step 6: Native TypeScript

interface User {
  id: number;
  name: string;
}

function getUser(id: number): User {
  return { id, name: "Alice" };
}
deno run app.ts

No transpilation needed.

Step 7: Deno bundler

deno bundle server.ts dist/server.js

Step 8: Deno tests

import { assertEquals } from "https://deno.land/[email protected]/assert/mod.ts";

Deno.test("add", () => {
  assertEquals(1 + 1, 2);
});
deno test

Step 9: Deno in production

Systemd:

[Service]
ExecStart=/root/.deno/bin/deno run --allow-net --allow-env /var/www/myapp/server.ts

Or use Deno Deploy for managed serverless.

Step 10: Compare to Node.js

CriterionNode.jsBunDeno
PerfReference~3x fastersimilar
TypeScriptNeed transpilerNativeNative
Node compatibility100%~90%Via npm:
PermissionsNoneNoneStrict opt-in
Package managernpm/yarn/pnpmbun built-inURL imports
EcosystemVery matureGrowingSmall but growing
StabilityExcellentGrowingGood

Step 11: When to use which

  • Node.js: ecosystem, stability, trained team
  • Bun: replace Node for perf, especially npm install
  • Deno: new TypeScript project, security focus, web standards

Step 12: Hybrid

Use Bun as package manager + bundler for a Node app:

bun install
bun build src/index.ts --outfile dist/index.js
node dist/index.js

Speed gain on install/build, prod still on Node.

Troubleshooting

Bun: "Module not found"

Bun struggles with some native modules (sharp, canvas). Check:

bun pm ls

If stuck, fall back to Node for this app.

Deno: "Cannot find module"

Check import URL. For npm modules:

import express from "npm:express@4";

Allow:

deno run --allow-net --allow-read --allow-env app.ts

Low performance in cluster

Bun and Deno don't natively support cluster mode like Node. Use a load balancer in front of multiple processes.

Useful commands

Bun

bun --version
bun init
bun install
bun add <pkg>
bun run <script>
bun build <file>
bun test
bun upgrade

Deno

deno --version
deno init
deno run --allow-net app.ts
deno task <task>
deno test
deno fmt
deno lint
deno bundle
deno upgrade

Conclusion

Bun and Deno are mature alternatives for 2026:

  • Bun for perf and Node compatibility
  • Deno for security and first-class TypeScript

Going further:

  • Test Bun as npm install replacement (immediate gain)
  • Explore Deno Deploy for serverless
  • For edge computing, check Cloudflare Workers (Wasm/V8 isolates)

Resources

Join our Discord community server

For any questions, suggestions, or just to chat with the community, join us on Discord!

900+Members