Deno
JavaScript
TypeScript
Runtime
Segurança
Permissões
Deploy
CLI
Modules
Web APIs

Introduction to Deno: Practical Guide for Modern Development

Deno, created by Ryan Dahl (the same creator of Node.js), arrived as a secure and modern alternative to the traditional JavaScript runtime.

Introduction to Deno: Practical Guide for Modern Development

Deno, created by Ryan Dahl (the same creator of Node.js), arrived as a secure and modern alternative to the traditional JavaScript runtime. Launched in 2020, Deno features native support for TypeScript, a restrictive permissions model, and a set of integrated tools (formatter, linter, test runner).

Why choose Deno?

  • Security by default, the process does not have access to files, network or environment without the developer explicitly granting it.
  • Native support for TypeScript, eliminates the need for external compilers.
  • ES-M Modules, imports via URLs simplify dependency management.
  • Integrated tools, deno fmt, deno lint and deno test come ready-made, reducing dependence on external packages.

Quick installation

curl -fsSL https://deno.land/x/install/install.sh | sh ## ou via Homebrew brew install deno

The script adds the binary to $PATH.

Structure of a Deno project

A typical Deno project maintains a lean organization. At the root are deno.json, which defines permissions, import-map and lint options, and README.md. The source code goes under the directory src/, with the entry point at main.ts and the helper modules in files like utils.ts. The tests are isolated in tests/, following the convention of names with a suffix _test.ts, such as main_test.ts.

Permissions, the heart of security

When running a script, you must specify which resources it can access:

PermissionDescription
--allow-readReading files or directories.
--allow-writeWriting to files or directories.
--allow-netNetwork connections (HTTP, TCP, UDP).
--allow-envAccess to environment variables.
--allow-runExecution of subprocesses.
--allow-ffiForeign Function Interface (C).

Safe execution example

deno run --allow-net src/main.ts

The script can make HTTP requests, but not read local files.

ES-M modules via URL

Deno allows you to import directly from public URLs:

import { serve } from "https://deno.land/std@0.203.0/http/server.ts";

The module is cached in ~/.deno and can be versioned via tag.

Creating a simple HTTP server

import { serve } from "https://deno.land/std@0.203.0/http/server.ts"; const handler = (request: Request): Response => { const url = new URL(request.url); if (url.pathname === "/") { return new Response("Olá Deno!", { status: 200 }); } return new Response("Not Found", { status: 404 }); }; serve(handler, { port: 8000 });

The code above creates a server that responds Olá Deno! at the root.

Integrated tests

Deno includes a lightweight test runner:

denon test --allow-net tests/main_test.ts

The test may use assertEquals from the standard library.

Test example (3 lines)

import { assertEquals } from "https://deno.land/std@0.203.0/testing/asserts.ts"; Deno.test("soma", () => assertEquals(2 + 2, 4));

Deploy in production

  • Docker, official image denoland/deno simplifies deployment.
FROM denoland/deno:alpine-1.38.0 WORKDIR /app COPY . . RUN deno cache src/main.ts EXPOSE 8000 CMD ["run", "--allow-net", "src/main.ts"]
  • Edge, Deno Deploy (service serverless) accepts scripts directly via URL.
  • CI/CD, GitHub Actions with deno lint && deno test && deno fmt --check guarantees quality.

Good security practices

  1. Minimum permissions, grant only what is necessary (--allow-read=./data).
  2. Lockfile, use deno lock to lock module versions.
  3. Dependency audit, check external URLs before trusting.
  4. Vulnerability scanning, tools like trivy can analyze the Docker image.

Quick checklist to start a Deno project

  • Install Deno (curl or brew).
  • Create deno.json with minimum permissions.
  • Structure directories (src, tests).
  • Write code using imports via URL.
  • Add unit tests.
  • Configure CI (lint, test, fmt).
  • Containerize with Docker or use Deno Deploy.
  • Review permissions before deployment.

Conclusion

Deno offers a secure, modern, and production-ready environment with fewer external dependencies. By adopting its restrictive permissions practices, ES-M modules, and integrated tools, developers can accelerate the delivery of robust applications and maintain a high standard of security.


What is your experience with Deno? Share in the comments!

Also read