Deno 2.0 is Here
What is this "DENO"?1
Let's Start!2
Node.js and NPM Support in Deno 2.03
What is this "DENO"?
Deno is a JavaScript runtime, kind of like Node.js, and itΓÇÖs made by the same guyΓÇöRyan Dahl. He built Deno to fix some of the issues with Node and make it better for cloud environments. ItΓÇÖs written in Rust, so yeah, it's blazingly fast. Now, let's check out some of Deno's cool features!
Setup Deno
ItΓÇÖs very easy to setup deno just run this command for Mac
curl -fsSL https://deno.land/install.sh | sh
For Windows
irm https://deno.land/install.ps1 | iex
And voilà, Deno is installed! Just restart your terminal, and you're good to go.
In-Built Tools
Deno comes packed with a bunch of built-in tools, so you donΓÇÖt have to stress about things like linting, formatting, running tests, or even setting up TypeScript configurations (and we all know setting up TypeScript can be a pain). If you want to use TypeScript in Deno, just change the file extension from .js to .tsΓÇöthat's literally all you need to do!
Another awesome feature of Deno is that it can compile your code into a standalone executable, letting you run it on any platform. This means you can instantly create a self-contained program from your Deno code. Plus, it even supports cross-compiling, so you can build for other platforms with ease!
Let's Start!
We will start by build our first Deno program and run it! Just type:
deno init
Some how if your VSCode dosenΓÇÖt recognize deno install these two extensions they will fix that.
This will create a basic project setup with a deno.json file and a main.ts file. It uses DenoΓÇÖs Standard Library (yep, they have their own standard libraryΓÇöhow cool is that?). Now you're all set to start coding with Deno!
HTTP Server -
LetΓÇÖs set up a basic HTTP server in Deno to handle routing. Deno makes it simple, as it comes with a built-in server setup. We just need to give it a handler function, and we're good to go. HereΓÇÖs how it works:
const HELLO_ROUTE = new URLPattern({ pathname: "/hello" });
const PORT = Deno.env.get("PORT") || 8080;
Deno.serve(
{
port: typeof PORT === "string" ? parseInt(PORT, 10) : PORT,
hostname: "127.0.0.1",
onListen({ port, hostname }) {
console.log(`Server started at http://${hostname}:${port}`);
},
},
(req: Request) => handler(req)
);
const handler = (req: Request): Response => {
const method = req.method;
const match = HELLO_ROUTE.exec(req.url);
if (match && method === "GET") {
const json = JSON.stringify({ message: "Yeah, it's working!" });
return new Response(json, {
status: 200,
headers: { "content-type": "application/json" },
});
} else {
return new Response("Not found", { status: 404 });
}
};
- We define HELLO_ROUTE using URLPattern to match requests to /hello.
- The server listens on a specified port, defaulting to 8080 if no environment variable is set.
- Our handler checks the request method and URL. If itΓÇÖs a GET request to /hello, we respond with a JSON message. Otherwise, it returns a 404 with ΓÇ£Not found.ΓÇ¥
We run our program by this command:
deno run <file-name.ts>

Deno will ask for permission every time you run the server, which is a safety feature in it (will explain later), but this can get annoying some times so you can use this below command or add this in deno.json as a task and run that.
deno run --watch --allow-read --allow-env --allow-net main.ts
This command gives Deno the necessary permissions upfrontΓÇölike reading files, accessing environment variables, and network permissions.
Node.js and NPM Support in Deno 2.0
One of the best things about Deno 2.0 is its support for Node.js and NPM libraries! This feature makes it super easy to bring over old Node projects to Deno with minimal effort.
LetΓÇÖs set up a simple server in Deno using Express from NPM. To pull in an NPM package, just add "npm:" before the package name, like "npm:express@version". Some packages might not come with types, but no worriesΓÇöyou can add types manually using the @deno-types directive. For example, you could bring in types with a @types package, and youΓÇÖre good to go! Here is an example to import express.js and it's types
// @deno-types="npm:@types/express@^4.17"
import express from "npm:express@^4.17";
With Deno, you donΓÇÖt need to install packages every timeΓÇötheyΓÇÖre cached globally. But, if you need a node_modules directory locally, just add "nodeModulesDir": "auto" in your deno.json file. This will automatically create a node_modules folder in your workspace. Also, if you have a package.json file, Deno will set up node_modules for you!
For more refrence you can go here .
Here is a simple example for the express server with a simple route as we know.
import "jsr:@std/dotenv/load";
// @deno-types="npm:@types/express@4"
import express, { Request, Response } from "npm:express@4.18.2";
import chalk from "npm:chalk";
const PORT = Deno.env.get("PORT") || 8080;
const app = express();
app.get("/", (_req: Request, res: Response) => {
console.log(chalk.bgCyan("Welcome to the Dinosaur API!"));
res.send("Welcome to the Dinosaur API!");
});
app.listen(PORT, () => {
console.log(`App is listening to port ${PORT}`);
});
Extra Features
Permissions for Enhanced Security
Next up, let's dive into one of DenoΓÇÖs key security features: permissions. By default, Deno requires user permission for actions like reading files, making HTTP requests, or accessing environment variables. This setup minimizes the risk of malicious code running on your system.
Compile to a Standalone Executable
With Deno, you can turn your program into a standalone file, making it runnable on any platform. Just use the command
deno compile --allow-read --allow-env --allow-net main.ts

This command compiles your code into an executable, bundling all necessary permissions like reading files, accessing environment variables, and network access. Now youΓÇÖve got a portable, self-contained app!
More Features
You can explore more features, like the built-in linter and formatter, on the official Deno website. Hope you enjoyed this guide! Let me know if youΓÇÖd like more content on Deno.