💻 Programming

Deno

Deno

A JS/TS runtime created by the creator of Node.js. Security and built-in TypeScript support.

📖 Detailed Explanation

Deno is a JavaScript/TypeScript runtime that Ryan Dahl unveiled in 2018 at JSConf EU, together with a talk titled "10 Things I Regret About Node.js." It was rebuilt from scratch in Rust to address design flaws in Node.js, and it uses the V8 engine to run JavaScript.

Deno's most notable feature is Secure by Default. Access to the file system, network, and environment variables requires explicit permission flags (--allow-read, --allow-net, etc.), which protects the system from malicious packages.

It natively supports TypeScript without extra configuration, and manages dependencies through URL-based module imports without package.json or node_modules. The built-in formatter (deno fmt), linter (deno lint), and test runner (deno test) simplify setting up the development environment.

Deno Deploy is a serverless platform that runs Deno applications at more than 35 edge locations around the world. When used with the Fresh framework, it can build fast web applications with zero JS bundles, and since 2024, npm package compatibility has also improved significantly.

💻 Code Example

// 1. HTTP 서버 (Deno.serve - 권장 방식)
Deno.serve({ port: 8000 }, (req: Request) => {
    const url = new URL(req.url);

    if (url.pathname === "/api/hello") {
        return Response.json({ message: "안녕하세요, Deno!" });
    }

    return new Response("Welcome to Deno", {
        headers: { "content-type": "text/plain" },
    });
});
// 실행: deno run --allow-net server.ts

// 2. 파일 읽기/쓰기 (권한 필요)
async function processFile() {
    // 파일 읽기 (--allow-read 필요)
    const content = await Deno.readTextFile("./data.json");
    const data = JSON.parse(content);

    // 데이터 처리
    data.updatedAt = new Date().toISOString();

    // 파일 쓰기 (--allow-write 필요)
    await Deno.writeTextFile(
        "./output.json",
        JSON.stringify(data, null, 2)
    );
    console.log("파일 처리 완료!");
}

// 3. URL 기반 모듈 임포트
import { serve } from "https://deno.land/std@0.220.0/http/server.ts";
import { assertEquals } from "https://deno.land/std@0.220.0/assert/mod.ts";

// npm 패키지도 사용 가능 (Deno 1.28+)
import express from "npm:express@4";
import chalk from "npm:chalk@5";

// 4. Deno KV (내장 키-값 저장소)
const kv = await Deno.openKv();

// 데이터 저장
await kv.set(["users", "user123"], {
    name: "홍길동",
    email: "hong@example.com"
});

// 데이터 조회
const result = await kv.get(["users", "user123"]);
console.log(result.value); // { name: "홍길동", ... }

// 5. 테스트 (deno test로 실행)
Deno.test("덧셈 테스트", () => {
    assertEquals(1 + 2, 3);
});

Deno.test("비동기 테스트", async () => {
    const response = await fetch("https://api.example.com/health");
    assertEquals(response.status, 200);
});

🗣️ Say It Like This in Practice

💬 In a Meeting
"I think we should build this microservice with Deno. You can use it right away without TypeScript configuration, and the security permission system can block unauthorized file/network access by third-party packages. If we deploy with Deno Deploy, the cold start is also under 50ms."
💬 In an Interview
"Unlike Node.js, Deno has security enabled by default. You have to explicitly grant permissions, such as --allow-net for network access and --allow-read for reading files. It also manages dependencies without node_modules through a URL-based module system, and pins versions with deno.lock."
💬 In a code review
"When you run this script, please specify only the permissions it needs instead of --allow-all. Specifying paths and hosts like --allow-read=./data --allow-net=api.example.com is safer. Also, if you set up an import map in deno.json, you can manage URL imports cleanly."

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

⚠️ Common Mistakes & Cautions

❌
Avoid overusing --allow-all

It is easy to use --allow-all for development convenience, but it removes Deno's security benefits. In production, always grant only the minimum necessary permissions, such as --allow-read and --allow-net.

❌
Pin versions in URL imports

Importing without a version, like https://deno.land/x/module/mod.ts, can cause unexpected updates. Always specify a version such as @0.1.0, and commit the deno.lock file.

✅
Take advantage of npm compatibility

Since Deno 1.28, you can use npm packages directly with npm:package-name. Use the existing Node.js ecosystem, such as Express and Prisma, in Deno as well. package.json is also supported.

🔗 Related Terms

📚 Learn More