Skip to content
Tutorials Center
My learning

Topics

Lesson 4 of 37 ยท Getting Started

Deno vs Node.js

Compare Deno and Node.js on modules, TypeScript, permissions, APIs, tooling and packages. Learn what is the same, what differs, and how to move code between the two.

Anyone who learns Deno is asked the same question: "Why not just use Node.js?" The honest answer is that they are two runtimes with the same engine and the same language, and they solve the same problems with different defaults. Node.js has a huge ecosystem and a decade of production use. Deno has a cleaner starting point and a security model. In 2024, Deno 2 closed much of the compatibility gap, so you can mix them more than before.

This lesson compares them side by side so you can decide, and so you can read code written for either. If you also know Node.js, the Node.js tutorial covers the other side in depth.

The big picture

Topic Node.js Deno
Engine V8 V8
Written in C++ Rust
TypeScript Needs a build tool or recent type stripping Built in
Modules CommonJS and ES modules ES modules (CommonJS only in compatibility cases)
Security Full access by default (opt-in permission model exists) No access by default, permissions per capability
Dependencies npm install into node_modules Import by URL, jsr: or npm:; global cache
Config package.json, tsconfig.json, many tool files One optional deno.json
Tooling Third-party (ESLint, Prettier, Jest, ...) Built in (fmt, lint, test, bench, compile)
Web APIs Many added over time (fetch, streams, ...) Web standards from day one
Standard library Large built-in node: modules Small core plus the reviewed @std packages

Neither is "better" in every case. The right choice depends on your team, your dependencies and where the code will run.

Modules and dependencies

Node.js traditionally installs packages into a project folder and resolves bare names like express from node_modules. Deno resolves a specifier that says exactly where code comes from:

TypeScript
import { assertEquals } from "jsr:@std/assert@1"; // JSR registry
import express from "npm:express@4";               // npm package
import { serve } from "https://deno.land/std/http/mod.ts"; // URL
import { join } from "node:path";                  // Node built-in
import { helper } from "./helper.ts";              // local, extension required

Two details trip up newcomers. Local imports must include the file extension, because Deno follows what the browser does. And there is no automatic index.js lookup. ES Modules and URL Imports goes through it.

In Deno 2 you can also keep using package.json and node_modules, so an existing Node project often runs with little change. See JSR and npm Packages.

Security

Run the same script in both:

TypeScript
const text = await Deno.readTextFile("secrets.txt");

In Node.js the equivalent readFile just works. In Deno it fails or prompts unless you pass --allow-read. Node.js added an opt-in --permission flag, but it is off by default, while in Deno it is the default. You will use permissions in every real project.

Globals and APIs

Both runtimes now offer fetch, URL, AbortController, TextEncoder, structuredClone and crypto. The differences are the system APIs:

  • Node.js: process, Buffer, require, __dirname, and modules like fs and http.
  • Deno: the Deno namespace (Deno.readTextFile, Deno.serve, Deno.env) plus import.meta.dirname.

Deno 2 also makes process, Buffer and the node: modules available when you opt in through an import, so Node-style libraries work. Node's node: modules can be imported in Deno using the same prefix.

The next example imports node:path and node:os, which behave the same in Deno and Node.js. Try it.

Node.js node: modules work in both

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Moving from CommonJS to ESM

Most Node.js code you find online uses require. Deno uses import. The conversion is mechanical:

Node.js CommonJS idea, ESM style

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

In Deno code, use import.meta.dirname and import.meta.filename instead of __dirname and __filename, and import.meta.url when you need a file URL.

Tooling

A typical Node.js project combines many tools: TypeScript, ESLint, Prettier, a test runner, a bundler, ts-node or tsx. Deno includes its own for each:

Need Node.js Deno
Run TypeScript tsx, ts-node, or Node's own flag deno run
Format Prettier deno fmt
Lint ESLint deno lint
Test Jest, Vitest, node:test deno test
Single executable pkg, SEA deno compile

Built-in tools are less flexible than the plugin ecosystems, but they start working immediately and have no version drift.

Performance and compatibility

Both use V8, so plain JavaScript runs at similar speed. Real differences show up in startup time, HTTP server throughput and the speed of specific APIs, and those change from release to release, so measure your own workload instead of trusting a headline benchmark.

For compatibility, Deno runs the large majority of popular npm packages. The remaining gaps are mostly native addons that need Node's internal C++ API. If you depend on one, test it before committing.

Choosing

A practical rule of thumb:

  • New scripts, CLIs, small services, edge code: Deno's defaults save time.
  • Existing large Node.js application with many native dependencies: stay on Node.js, or migrate piece by piece.
  • Library authors: publish to JSR or npm and test on both runtimes.
flowchart TD
  A["New project?"] -->|Yes| B["Want TypeScript and permissions by default?"]
  A -->|"No, existing Node app"| C["Does it use native addons?"]
  B -->|Yes| D["Choose Deno"]
  B -->|No| E["Either works"]
  C -->|Yes| F["Stay on Node.js"]
  C -->|No| G["Try running it in Deno 2"]

A rough decision path, not a rule.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What is true about local imports in Deno?

    Deno follows the browser: you write the full path, for example ./helper.ts, with no extension guessing.
  2. 2. Which is the default security behaviour?

    Deno denies system access until permitted. Node.js allows it by default, with an optional permission flag.
  3. 3. What replaces __dirname in a Deno ES module?

    import.meta.dirname and import.meta.filename are the ES module equivalents.
  4. 4. Which Deno command replaces Prettier?

    deno fmt is the built-in code formatter.
  5. 5. Which statement about Deno 2 is accurate?

    Deno 2 added broad npm and package.json compatibility, though node_modules is optional.

Summary

  • Both runtimes use V8; they differ in defaults, not in the language.
  • Deno has built-in TypeScript, ES modules only, permissions and bundled tools.
  • Deno resolves imports by explicit specifier: URL, jsr:, npm:, node: or a path with extension.
  • Deno 2 runs most npm code and respects package.json.
  • Convert require to import, and __dirname to import.meta.dirname.
  • Choose by project needs and test your dependencies.

Next: TypeScript in Deno