DEV Community

Cover image for What's New in Deno 2
Rahul Sharma
Rahul Sharma

Posted on

What's New in Deno 2

When Deno first came out, it shook up the JavaScript and TypeScript world with some fresh ideas. It was created by Ryan Dahl, the same guy who made Node.js, and Deno was meant to solve some of Node’s issues, like security and how modules work. Now, Deno 2 is here and it’s got even more features and improvements, making it a powerful choice for backend development.

Deno 2 brings tons of updates to make development easier, faster, and more secure. Here are some of the key improvements:

Backwards-Compatible and Future-Ready

Deno 2 works smoothly with Node and npm, meaning you can use it alongside your current Node projects. For example, after cloning a Node project, you can use deno install to quickly set up dependencies or deno fmt to format your code without needing Prettier.

Deno 2 handles package.json, node_modules, and npm workspaces, so it can run in any Node project using ESM. For minor syntax issues, just use deno lint --fix.

If you don't like package.json and node_modules but still want to use npm packages, you can import them directly using npm: specifiers. This lets you write programs with npm dependencies in a single file—no extra configuration needed.

import chalk from "npm:chalk@5.3.0";
console.log(chalk.blue("Hello, world!"));
// Hello, world! (in blue)
Enter fullscreen mode Exit fullscreen mode

For larger projects, you can manage dependencies with a manifest file. Place an npm: specifier in a deno.json file to import the package easily:

// deno.json
{
  "imports": {
    "chalk": "npm:chalk@5.3.0"
  }
}
Enter fullscreen mode Exit fullscreen mode
import chalk from "chalk";
console.log(chalk.blue("Hello, world!"));
// Hello, world! (in blue)
Enter fullscreen mode Exit fullscreen mode

Deno lets you access over 2 million npm modules, including complex packages like gRPC, ssh2, Prisma, temporal.io, duckdb, polars, and even supports Node-API native addons.

You can also use Deno 2 with your favorite JavaScript frameworks like Next.js, Astro, Remix, Angular, SvelteKit, QwikCity, and more. It’s versatile and powerful for modern web development.

Deno Now Works as a Package Manager

Deno 2 not only supports package.json and node_modules, but it also introduces three key subcommands to manage your dependencies effortlessly.

deno install: This command installs your dependencies at lightning speed. If you have a package.json, it will create a node_modules folder in an instant. Without a package.json, it caches all dependencies globally. It’s 15% faster than npm with a cold cache and 90% faster with a hot cache.

deno add and deno remove: These commands let you add or remove packages in your package.json or deno.json. If you’ve used npm install or npm remove, you’ll feel right at home.

New JavaScript Registry (JSR)

Earlier this year, Deno team launched JSR, a modern and open-source JavaScript registry. It’s a game-changer because it supports TypeScript natively, letting you publish modules directly as TypeScript source code. JSR handles the complex task of loading modules across different runtimes and environments, supports only ESM, auto-generates documentation from JSDoc-style comments, and works with npm- and npx-like systems. It even converts TypeScript into .js and .d.ts files.

The Deno Standard Library is Now Stable

The Deno Standard Library is packed with thoroughly reviewed utility modules for everything from data manipulation to web-related logic and JavaScript-specific functionalities. It’s available on JSR and works with other runtimes and environments.

Private npm Registries and More

Deno 2 handles private npm registries just like Node and npm. All you need is an .npmrc file. Deno will automatically detect it and allow you to pull private packages without any extra setup.

// .npmrc
@mycompany:registry=http://mycompany.com:8111/
//mycompany.com:8111/:_auth=secretToken
Enter fullscreen mode Exit fullscreen mode

Workspaces and Monorepos

Deno 2 supports workspaces, making it easy to manage monorepos. Just list the member directories in your deno.json:

// deno.json
{
  "workspace": ["./add", "./subtract"]
}
Enter fullscreen mode Exit fullscreen mode

Members can have separate dependencies and configuration. Deno also understands npm workspaces, allowing for hybrid Deno-npm monorepos. You can publish workspace members to JSR with deno publish.

Long Term Support (LTS)

For larger organizations, auditing new releases can be time-consuming. That’s why Deno is introducing an LTS release channel starting with Deno 2.1. This channel will receive critical bug fixes for six months, ensuring a stable base for production use. After six months, a new LTS branch will be created based on the latest stable version.


Must Read If you haven't

More content at Dev.to.
Catch me on

Youtube Github LinkedIn Medium Stackblitz Hashnode HackerNoon

Top comments (0)