TechSetupGuides
Beginnerdenojavascripttypescriptruntimeweb-standardssecuritynpmnode.jsjupyterweb-apiedgecloudclitoolchain

Deno - Modern JavaScript/TypeScript Runtime

Install and use Deno, the secure next-generation JavaScript/TypeScript runtime with built-in TypeScript support, zero-config tooling, web-standard APIs, and enterprise-grade security — covering installation, configuration, CLI tools, and common use cases.

  1. Step 1

    Overview

    Deno is a modern, secure runtime for JavaScript and TypeScript built on web standards. Created by Ryan Dahl (the original creator of Node.js), Deno addresses many of Node.js's architectural challenges while adding powerful new features.

    Key Features:

    • Secure by Default: No file system, network, or environment access unless explicitly granted
    • TypeScript First: Native TypeScript support with zero configuration
    • Web Standards: Built on web APIs that work the same in browser and server
    • Complete Tooling: Built-in test runner, formatter, linter, and documentation generator
    • Single Binary: No external dependencies, downloads in seconds
    • Node Compatibility: Seamless npm package and Node.js built-in module support
    • Modern Architecture: Based on V8, libuv, and Rust with async/await
    • Enterprise Ready: Production deployments at Netflix, GitHub, Supabase, Stripe, Slack, and 400k+ users

    Why Deno:

    • Security: Sandboxed by default, explicit permissions
    • Developer Experience: Zero-config TypeScript, built-in tools
    • Web Standards: Future-proof APIs that match the browser
    • Performance: Fast startup, efficient execution
    • Simplicity: One binary, no complex dependency management
    Official site: https://deno.com
    GitHub: https://github.com/denoland/deno (100K+ stars)
    Documentation: https://docs.deno.com
    JSR Package Registry: https://jsr.io
    Deno Deploy (Edge Platform): https://deno.com/deploy
  2. Step 2

    Quick Installation

    Deno runs on macOS, Linux, and Windows. It's a single binary with no external dependencies.

    Supported platforms:

    • macOS: Intel (x64) and Apple Silicon (arm64)
    • Windows: x64 and ARM64
    • Linux: x64

    Installation methods:

    1. Shell script (recommended) - fastest, best performance
    2. npm - convenient but slower startup
    3. Homebrew (macOS) - macOS package management
    4. Other package managers - Nix, asdf, vfox
    # Option 1: Shell Script (Recommended)
    # Fastest startup, best performance
    curl -fsSL https://deno.land/install.sh | sh
    
    # Option 2: npm (Convenient but slower startup)
    npm install -g deno
    
    # Option 3: Homebrew (macOS only)
    brew install deno
    
    # Option 4: asdf Version Manager
    asdf plugin add deno https://github.com/asdf-community/asdf-deno.git
    asdf install deno latest
    asdf set -u deno latest
    
    # Option 5: vfox Version Manager
    vfox add deno
    vfox install deno@latest
    vfox use --global deno
    
    # Option 6: Nix
    nix-shell -p deno
    
    # Option 7: Cargo (from source)
    cargo install deno --locked
    
    # Option 8: Winget (Windows)
    winget install DenoLand.Deno
    
    # Verify installation
    deno --version
    # Should print something like: deno 2.0.x
    
    # View the help documentation
    deno help
  3. Step 3

    Running Code & the Permissions Model

    Deno runs .js and .ts files directly — no build or transpile step. Its defining trait is that scripts are sandboxed: they cannot touch the filesystem, network, or environment unless you grant access with explicit flags. This is the opposite of Node.js, where any script has full access by default.

    Grant only what a script needs (least privilege), or use -A to allow everything during development.

    # Run a local file
    deno run main.ts
    
    # Run straight from a URL
    deno run https://docs.deno.com/examples/hello-world.ts
    
    # Granular permissions
    deno run --allow-net main.ts            # network only
    deno run --allow-read=./data main.ts    # read a specific dir
    deno run --allow-env --allow-net api.ts # env vars + network
    
    # Allow everything (dev convenience)
    deno run -A main.ts
    
    # REPL and one-off evaluation
    deno repl
    deno eval "console.log(1 + 2)"
    ⚠ Heads up: Prefer scoped permissions (e.g. `--allow-read=./data`) over blanket `-A` in anything that runs untrusted code or ships to production.
  4. Step 4

    Project Configuration (deno.json)

    A deno.json (or deno.jsonc) at the project root configures the runtime, tasks, dependencies, and tool settings. Deno auto-discovers it — no flag needed. It replaces much of what package.json, tsconfig.json, and a bundler config do in a Node project.

    Use tasks for script shortcuts (deno task dev), imports for bare-specifier import maps, and compilerOptions to tune TypeScript.

    {
      "tasks": {
        "dev": "deno run --watch --allow-net main.ts",
        "start": "deno run --allow-net main.ts",
        "test": "deno test --allow-read"
      },
      "imports": {
        "@std/assert": "jsr:@std/assert@^1.0.0",
        "oak": "jsr:@oak/oak@^17"
      },
      "compilerOptions": {
        "strict": true,
        "lib": ["deno.window"]
      },
      "fmt": { "lineWidth": 100, "singleQuote": false },
      "lint": { "rules": { "tags": ["recommended"] } }
    }
  5. Step 5

    Built-in Toolchain

    Deno ships a full toolchain in the single binary — no installing ESLint, Prettier, Jest, ts-node, or a bundler. Every command works zero-config but respects deno.json when present.

    These cover formatting, linting, testing, type-checking, documentation, and producing standalone executables.

    deno fmt              # format code (Prettier-style)
    deno lint             # lint with recommended rules
    deno test             # run *_test.ts / *.test.ts files
    deno test --coverage  # collect coverage
    deno check main.ts    # type-check without running
    deno doc main.ts      # generate docs from JSDoc
    deno bench            # run benchmarks
    
    # Compile to a self-contained executable
    deno compile --allow-net -o server main.ts
    
    # Keep deps and the toolchain current
    deno upgrade
  6. Step 6

    Managing Dependencies (npm, JSR, import maps)

    Deno has no node_modules install step by default — it caches remote modules on first use. You can import from three main sources:

    • JSR (jsr:) — the modern JavaScript registry, Deno's preferred source
    • npm (npm:) — the entire npm ecosystem works via the npm: specifier
    • HTTPS URLs — import directly from any URL

    Map long specifiers to short names in the imports block of deno.json so application code stays clean.

    // Direct specifiers
    import { serve } from "jsr:@std/http";
    import express from "npm:express@4";
    import { z } from "npm:zod";
    
    // With an import map in deno.json:
    //   "imports": { "@std/assert": "jsr:@std/assert@^1.0.0" }
    import { assertEquals } from "@std/assert";
    
    assertEquals(1 + 1, 2);
    
    // Add dependencies from the CLI (writes to deno.json)
    // $ deno add jsr:@oak/oak
    // $ deno add npm:chalk
    //
    // Pre-cache all deps (e.g. in CI / Docker build):
    // $ deno install
  7. Step 7

    Common Use Cases

    Because Deno implements web-standard APIs (fetch, Request, Response, URL, Web Streams), the same code often runs in the browser, on the server, and at the edge. Typical uses:

    • HTTP servers & APIs via the built-in Deno.serve
    • Scripting & automation — single-file tools with scoped permissions, runnable straight from a URL
    • Edge functions deployed to Deno Deploy, Supabase Edge Functions, or Cloudflare
    • Jupyter notebooks via the built-in kernel (deno jupyter --install)

    The example below is a complete, dependency-free HTTP server.

    // server.ts — run with: deno run --allow-net server.ts
    Deno.serve({ port: 8000 }, (req: Request) => {
      const url = new URL(req.url);
    
      if (url.pathname === "/") {
        return new Response("Hello from Deno!");
      }
    
      if (url.pathname === "/api/time") {
        return Response.json({ now: new Date().toISOString() });
      }
    
      return new Response("Not Found", { status: 404 });
    });
    
    // Deploy globally:
    //   deno deploy   (https://deno.com/deploy)

Feature requests

Sign in to suggest features or vote on existing ones.

No feature requests yet.

Discussion

0 people marked this as worked·Sign in to mark your own.

Sign in to join the discussion.

No comments yet.