DEV Community

Alex Spinov
Alex Spinov

Posted on

Deno Has a Free API: The JavaScript Runtime That Fixed Node.js

Ryan Dahl created Node.js. Then he created Deno to fix everything he regretted about Node.

What Is Deno?

Deno is a JavaScript/TypeScript runtime with security, built-in tooling, and web standard APIs. No node_modules. No package.json. No tsconfig.json. No webpack.config.js.

// server.ts — that's the whole file name, no config needed
Deno.serve((req: Request) => {
  const url = new URL(req.url);
  if (url.pathname === "/api/hello") {
    return Response.json({ message: "Hello from Deno!" });
  }
  return new Response("Not found", { status: 404 });
});
Enter fullscreen mode Exit fullscreen mode
deno run --allow-net server.ts
# Server running on http://localhost:8000
Enter fullscreen mode Exit fullscreen mode

TypeScript works out of the box. No ts-node. No tsc. No tsconfig.json.

Security by Default

# This FAILS — no permissions granted
deno run script.ts

# Explicit permissions
deno run --allow-net --allow-read=./data script.ts

# Prompted permissions
deno run --prompt script.ts
Enter fullscreen mode Exit fullscreen mode

Node.js: your npm package can read your SSH keys, send them to a server, and delete your files. Deno: nothing happens without explicit permission.

Built-in Everything

deno fmt          # Formatter (like Prettier)
deno lint         # Linter (like ESLint)
deno test         # Test runner (like Jest)
deno bench        # Benchmarking
deno compile      # Compile to standalone executable
deno jupyter      # Jupyter notebook kernel
deno doc          # Documentation generator
deno coverage     # Code coverage
Enter fullscreen mode Exit fullscreen mode

That's 8 tools that Node.js needs 8 separate npm packages for.

Deno KV: Built-in Database

const kv = await Deno.openKv();

// Set a value
await kv.set(["users", "123"], { name: "Alice", email: "alice@example.com" });

// Get a value
const user = await kv.get(["users", "123"]);
console.log(user.value); // { name: "Alice", ... }

// List values
const users = kv.list({ prefix: ["users"] });
for await (const entry of users) {
  console.log(entry.key, entry.value);
}
Enter fullscreen mode Exit fullscreen mode

A key-value database built into the runtime. On Deno Deploy, it's globally replicated.

Node.js Compatibility

// Import npm packages directly
import express from "npm:express@4";
import chalk from "npm:chalk@5";

// Node built-ins work too
import { readFileSync } from "node:fs";
Enter fullscreen mode Exit fullscreen mode

Most npm packages work. Express, Prisma, Next.js — all compatible.


Building modern JavaScript apps? Check out my developer tools or email spinov001@gmail.com.

Top comments (0)