Mar 23, '25 02:00

How to work with Deno: a new era for JavaScript and TypeScript developers

Deno is becoming an increasingly interesting choice for developers looking for an alternative to Node.js. This modular JavaScript runtime, created by Node.js author Ryan Dahl, aims to provide a more secure and modern approach to working with JavaScript and ...

Read post
Share
🔥 More posts
This content has been automatically translated from Ukrainian.

Deno is becoming an increasingly interesting choice for developers looking for an alternative to Node.js. This modular JavaScript runtime, created by Node.js author Ryan Dahl, aims to provide a more secure and modern approach to working with JavaScript and TypeScript. Let's explore what features and advantages Deno can offer to modern developers.

What is Deno?

Deno is an open runtime for JavaScript and TypeScript, based on V8 (the JavaScript engine from Google). Its key feature is built-in support for TypeScript, modularity, and access to powerful APIs without the need for external libraries.

Core principles of Deno:

  • Security. By default, Deno blocks access to files, the network, and the environment, reducing the risk of unexpected exploits.
  • Simplified module management. Deno uses URLs for module imports, eliminating the need for package.json or node_modules.
  • Modernity. Support for new JavaScript and TypeScript standards, allowing developers to take advantage of the latest language features.

Getting Started with Deno

Installing Deno

To use Deno, you first need to install it on your computer. It is available for Windows, macOS, or Linux. Here are the installation instructions via CLI:

curl -fsSL https://deno.land/x/install/install.sh | sh

After successful installation, run the command to check the Deno version:

deno --version

Writing Your First Program

Create a file hello.ts with the following content:

console.log("Hello, Deno!");

To run this file, use the command:

deno run hello.ts

As you start working, Deno automatically detects that the file is written in TypeScript and compiles it without any hassle.

Working with Modules and Packages

Deno supports importing modules directly from URLs. For example:

import { serve } from "https://deno.land/[email protected]/http/server.ts";

const s = serve({ port: 8000 });
console.log("HTTP webserver running. Access it at: http://localhost:8000/");

for await (const req of s) {
  req.respond({ body: "Hello, Deno!" });
}

Advantages:

  • Absence of node_modules. Deno caches modules globally, so there's no need to worry about large node_modules directories.
  • Version control. By importing modules from a specific URL (with a clearly specified version), you always know which version you are using.

Deno for Security

Deno configures file, network, and environment variable access through security flags. To grant access to these resources, use the appropriate flags:

  • --allow-read for reading files
  • --allow-write for writing files
  • --allow-net for network access

For example, the command to run a script that reads a file:

deno run --allow-read fileReader.ts

Deno brings many fresh ideas to the world of JavaScript and TypeScript development, placing a special emphasis on security and a modern approach. It is a great tool for those looking for a streamlined alternative to Node.js, especially when using TypeScript. With Deno, developers can enjoy a new level of freedom without sacrificing security or performance.

🔥 More posts

All posts