Lädt...


🔧 Intro to Deno vs Node


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

This is an introduction blog on Deno. Since Deno 2.0 was just launched on 9th Oct 2024. Therefore, I decided to write a blog for all those who do not know it. I am excited to try Deno 2.0.

// Detect dark theme var iframe = document.getElementById('tweet-1844059477240316322-31'); if (document.body.className.includes('dark-theme')) { iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1844059477240316322&theme=dark" }

Introduction

In simple words, Deno serves the same purpose as Node but has more features than what Node offers. In fact, both technologies are developed by the same person, Ryan Dahl. Compared to Node, Deno takes a security-first approach, which is discussed further. Since Deno and Node serve the same purpose, to explain Deno’s features, it is mostly compared with Node.

Deno vs Node

Following are a few differences of Deno over Node:

1. Security

The first thing is security. As mentioned earlier, Deno takes a security-first approach. For instance, working with a file in Node is straightforward; you just import the fs module, write the script, and run it. However, with Deno, although the process is similar, the script won’t run unless a specific flag is passed while executing it.

2. TypeScript Support

The second amazing feature over Node is the built-in TypeScript support. In Node, to use TypeScript, you first have to set up a TypeScript project with tsconfig.json, and then transpile the TypeScript code to JavaScript before running it. However, with Deno, you just need to create a .ts file and run it directly.

3. No node_modules and Config Files

Deno does not require any package manager to manage the modules in the project. Following is how various modules are imported:

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

This eliminates the requirement of the node_modules folder and any config file.

4. Support for Web APIs

The Fetch API is globally available in Deno, as opposed to in Node. In Node, you need to import the module to use the Fetch API to call an API; however, in Deno, you can directly use the Fetch method to call an API, just like in a browser.

For instance:

// Using the Fetch API to make a GET request
async function fetchData() {
    try {
        const response = await fetch("https://jsonplaceholder.typicode.com/posts/1");

        // Check if the response is ok (status in the range 200-299)
        if (!response.ok) {
            throw new Error(`HTTP error! Status: ${response.status}`);
        }

        // Parse the response as JSON
        const data = await response.json();

        // Log the retrieved data
        console.log("Fetched data:", data);

    } catch (error) {
        console.error("Error fetching data:", error);
    }
}

// Call the function to fetch data
fetchData();

5. Top-Level await Support

Deno allows the use of await anywhere in the file; it does not need to be wrapped in an async function.

This is how it works in Deno:

// Deno example using top-level await
const response = await fetch("https://api.example.com/data");
const data = await response.json();
console.log(data);

And this is how it works in Node:

// Node.js example (pre top-level await support)
(async () => {
    const response = await fetch("https://api.example.com/data");
    const data = await response.json();
    console.log(data);
})();

In Node, you can only use await inside an async function.

6. Built-in Testing Tools

Deno provides built-in testing tools, which means there is no need for additional setup or external libraries to install. In contrast, in Node, you need to choose and configure an external testing library.

Moreover, Deno 2.0 also has many new useful features to explore and assist in making programming fun and less complex.

Here is the Deno documentation to know more about it.

Final Words

Although Deno has a lot of cool features compared to Node, I feel it would still take time to be accepted by industries on a large scale since Node has been the trustworthy framework for the last few years and is well-known by companies as well as developers.

Let me know what you think about Deno.

...

🔧 Deno vs Node.js: Is Deno Really the Better Node?


📈 47.67 Punkte
🔧 Programmierung

📰 Node.js Rival Deno Gets Seed Capital For Full-time Deno Engineers


📈 40.71 Punkte
📰 IT Security Nachrichten

🔧 Intro to Deno vs Node


📈 36.42 Punkte
🔧 Programmierung

🔧 Deno Fresh PostCSS: Future CSS with Deno


📈 33.75 Punkte
🔧 Programmierung

🔧 Introduction to the Developer's Intro to Data Science Video Series (1 of 28) | Dev Intro to Data Science


📈 25.17 Punkte
🔧 Programmierung

🔧 Node vs Deno vs Bun: Comparing JavaScript Runtimes


📈 23.83 Punkte
🔧 Programmierung

🔧 Node.js-Alternative: JavaScript-Runtime Deno reaktiviert WebGL-Nachfolger WebGPU


📈 23.83 Punkte
🔧 Programmierung

🔧 #1 Daily Rabbit Holes: Rusty V8, Node.js and Deno


📈 23.83 Punkte
🔧 Programmierung

🔧 How to use the Fetch API in Node.js, Deno, and Bun


📈 23.83 Punkte
🔧 Programmierung

🔧 JavaScript-Runtime Deno 2.0: Ist die neue Version das bessere Node.js?!


📈 23.83 Punkte
🔧 Programmierung

🔧 Deno vs. Node: No One is Ready for the Move


📈 23.83 Punkte
🔧 Programmierung

🔧 Nx 15.8 - Rust Hasher, Nx Console for IntelliJ, Deno, Node and Storybook


📈 23.83 Punkte
🔧 Programmierung

🔧 Hono.js Benchmark: Node.js vs. Deno 2.0 vs. Bun — Which Is the Fastest?


📈 23.83 Punkte
🔧 Programmierung

📰 Die neue JavaScript-Runtime Bun fordert Node, Deno & Co. heraus


📈 23.83 Punkte
📰 IT Nachrichten

🔧 Is It Time to Say Goodbye to Node.js? (Deno 2.0 Got This)


📈 23.83 Punkte
🔧 Programmierung

📰 JavaScript-Laufzeitumgebung: Node.js-Konkurrent Deno weiß nun Firma hinter sich


📈 23.83 Punkte
📰 IT Nachrichten

🔧 Deno vs Node: The Next Evolution of JavaScript, But Are We Ready?


📈 23.83 Punkte
🔧 Programmierung

📰 Javascript: Node.js-Alternative Deno bekommt Finanzierung


📈 23.83 Punkte
📰 IT Nachrichten

📰 JavaScript-Runtime Deno 2.0 nimmt es mit Node.js auf


📈 23.83 Punkte
📰 IT Nachrichten

📰 Node.js/Deno Creator Discusses Rust, C++, TypeScript, and Vim


📈 23.83 Punkte
📰 IT Security Nachrichten

🔧 JavaScript-Runtime Deno 2.0 nimmt es mit Node.js auf


📈 23.83 Punkte
🔧 Programmierung

🔧 Besser als Node.js? Was Deno vom großen Bruder unterscheidet


📈 23.83 Punkte
🔧 Programmierung

🔧 Deno 2.0: The Next Evolution in JavaScript Runtimes – Is It Better Than Node.js?


📈 23.83 Punkte
🔧 Programmierung

📰 Node.js und Deno im Vergleich


📈 23.83 Punkte
📰 IT Nachrichten

🔧 Deno 2: A New Era or Just a Sidekick to Node.js?


📈 23.83 Punkte
🔧 Programmierung

🔧 Using Node Modules in Deno


📈 23.83 Punkte
🔧 Programmierung

🔧 Deno 2: A New Era or Just a Sidekick to Node.js?


📈 23.83 Punkte
🔧 Programmierung

🔧 Using Node Modules in Deno


📈 23.83 Punkte
🔧 Programmierung

📰 Addressing 'Design Mistakes' in Node.js, Its Developers Release JS/TypeScript Runtime Deno 1.0


📈 23.83 Punkte
📰 IT Security Nachrichten

🎥 Deno 2 is here… will it actually kill Node.js this time?


📈 23.83 Punkte
🎥 Video | Youtube

📰 Webentwicklung: Deno 1.0 soll Node.js als Framework für Skriptsprachen ersetzen


📈 23.83 Punkte
📰 IT Nachrichten

🎥 Will Deno 2.0 Replace Node.js?


📈 23.83 Punkte
🎥 Video | Youtube

🔧 Deno: Will It Replace Node.JS?


📈 23.83 Punkte
🔧 Programmierung

🕵️ CVE-2024-27935 | Deno Node.js Compatibility Runtime information disclosure


📈 23.83 Punkte
🕵️ Sicherheitslücken

matomo