DEV Community

Alex Spinov
Alex Spinov

Posted on

Deno 2 Has a Free API — Here's How to Use It

Deno 2 is the next evolution of the secure JavaScript and TypeScript runtime — and it ships with a free, built-in API that most developers don't know about.

What Changed in Deno 2?

Deno 2 brings backward compatibility with Node.js and npm, while keeping its security-first model. The key changes:

  • Full npm compatibilityimport npm:express works natively
  • Node.js built-in supportnode:fs, node:path all work
  • deno.json workspaces — monorepo support out of the box
  • Stable Deno.serve() — the fastest HTTP server API in any runtime

The Free API You're Missing

Deno Deploy gives you a free tier with:

  • 1M requests/month
  • 100 GiB data transfer
  • Automatic HTTPS and global edge deployment
  • KV storage (built-in database, no setup)
  • Cron jobs (scheduled tasks, zero config)
// server.ts — deploy for free on Deno Deploy
Deno.serve((req: Request) => {
  const url = new URL(req.url);

  if (url.pathname === "/api/data") {
    return Response.json({
      message: "Hello from Deno 2!",
      timestamp: Date.now(),
      runtime: Deno.version
    });
  }

  return new Response("Deno 2 API Server", { status: 200 });
});
Enter fullscreen mode Exit fullscreen mode

Built-in KV Database (Free!)

const kv = await Deno.openKv();

// Store data
await kv.set(["users", "user123"], { 
  name: "Alex", 
  plan: "free",
  signedUp: new Date().toISOString()
});

// Retrieve data
const user = await kv.get(["users", "user123"]);
console.log(user.value); // { name: "Alex", plan: "free", ... }

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

No database setup. No connection strings. No ORM. Just works.

Cron Jobs (Also Free)

Deno.cron("daily-cleanup", "0 0 * * *", async () => {
  const kv = await Deno.openKv();
  const oldEntries = kv.list({ prefix: ["temp"] });

  for await (const entry of oldEntries) {
    await kv.delete(entry.key);
  }
  console.log("Cleanup complete");
});
Enter fullscreen mode Exit fullscreen mode

Schedule tasks without crontab, without external services, without configuration files.

Quick Start

# Install Deno 2
curl -fsSL https://deno.land/install.sh | sh

# Create a project
deno init my-api

# Run with all permissions
deno run --allow-net server.ts

# Deploy to edge (free)
deno deploy
Enter fullscreen mode Exit fullscreen mode

Why Deno 2 Over Node.js?

Feature Deno 2 Node.js
TypeScript Native, zero config Requires ts-node/tsx
Security Permissions by default Full access by default
Package manager Built-in (no npm install) npm/yarn/pnpm
Formatter Built-in deno fmt Prettier (install separately)
Linter Built-in deno lint ESLint (install + config)
Test runner Built-in deno test Jest/Vitest (install + config)
Deploy Deno Deploy (free tier) Requires separate hosting
Database Built-in KV External DB required

Real-World Example: URL Shortener

const kv = await Deno.openKv();

Deno.serve(async (req: Request) => {
  const url = new URL(req.url);

  // Create short URL
  if (req.method === "POST" && url.pathname === "/shorten") {
    const { target } = await req.json();
    const id = crypto.randomUUID().slice(0, 8);
    await kv.set(["urls", id], target);
    return Response.json({ short: `${url.origin}/${id}` });
  }

  // Redirect
  const id = url.pathname.slice(1);
  const entry = await kv.get(["urls", id]);
  if (entry.value) {
    return Response.redirect(entry.value as string, 302);
  }

  return new Response("Not found", { status: 404 });
});
Enter fullscreen mode Exit fullscreen mode

Deploy this for free. Zero dependencies. Full URL shortener in 20 lines.


Need to scrape data from any website and get it in structured JSON? Check out my web scraping tools on Apify — no coding required, results in minutes.

Have a custom data extraction project? Email me at spinov001@gmail.com — I build tailored scraping solutions for businesses.

Top comments (0)