misakong

misakong

What's New in Deno 2

When Deno first emerged, it shook the JavaScript and TypeScript world with some new ideas. Created by Ryan Dahl, the founder of Node.js, Deno aims to address some of Node's issues, such as security and how modules work. Now, Deno 2 has arrived, bringing more features and improvements, making it a powerful choice for backend development.
Deno 2 comes with a plethora of updates that make development easier, faster, and safer. Here are some key improvements:

Backward Compatible and Future-Ready#

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

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

If you dislike package.json and node_modules but still want to use npm packages, you can import them directly using the npm: specifier. This allows you to write programs with npm dependencies in a single file without extra configuration.

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

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

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

Deno Now Acts as a Package Manager#

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

deno install: This command installs your dependencies at lightning speed. If you have a package.json, it will immediately create a node_modules folder. If there is no package.json, it will globally cache all dependencies. It is 15% faster than using cold cache npm and 90% faster than using hot cache npm.

deno add and deno remove: These commands allow you to add or remove packages in 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, the Deno team launched JSR, a modern open-source JavaScript registry. It changes the game by natively supporting TypeScript, allowing you to publish modules directly as TypeScript source code. JSR handles the complex task of loading modules across different runtimes and environments, supports only ESM, automatically generates documentation from JSDoc-style comments, and works with systems like npm and npx. It can even convert TypeScript to .js and .d.ts files.

Deno Standard Library Now Stable#

The Deno standard library includes thoroughly reviewed utility modules for everything from data manipulation to web-related logic and JavaScript-specific features. It is available on JSR and can be used with other runtimes and environments.

Private npm Registries, etc.#

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

Workspaces and Monorepos#

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

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

Long Term Support (LTS)#

For large organizations, auditing new releases can be very time-consuming. This is why Deno introduced the LTS release channel starting from Deno 2.1. This channel will receive critical bug fixes for six months to ensure a stable foundation for production use. After six months, a new LTS branch will be created based on the latest stable release.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.