Can Deno run apps and libraries authored for Node.js? What are the tradeoffs? How does it work? What’s next?
This talk has been presented at Node Congress 2022, check out the latest edition of this JavaScript Conference.
Can Deno run apps and libraries authored for Node.js? What are the tradeoffs? How does it work? What’s next?
This talk has been presented at Node Congress 2022, check out the latest edition of this JavaScript Conference.
Deno is a command-line runtime for JavaScript and TypeScript, similar to Node.js, but it supports TypeScript as a first-class citizen without requiring a separate build chain. Unlike Node.js, Deno utilizes secure execution by default, meaning programs can't access the file system, environmental variables, or the internet unless explicitly permitted.
Yes, Deno can execute Node.js applications and libraries using the --compat flag for compatibility and the --unstable flag due to some API limitations. However, not all Node.js APIs are fully supported yet, as Deno is still working on providing compatible APIs and polyfills.
Deno allows importing any third-party code using URLs directly, similar to browser ES module imports. This eliminates the need for a centralized package manager like npm, allowing code to be pulled from any public or private server. Deno fetches, caches, and compiles (or transpiles) this code transparently on the first run.
The main trade-offs include some Node.js APIs not being fully compatible or available in Deno, the need for additional flags to enable Node.js compatibility, and potential issues with native Node.js modules that rely on C++ APIs, which are not supported in Deno's Rust-based environment.
Deno emphasizes security by enforcing strict access controls. By default, Deno scripts run in a secure sandbox environment where access to system resources like the file system, environment variables, and network access is restricted unless explicitly granted via command-line flags.
While Deno offers many similar functionalities as Node.js and adds improvements like first-class TypeScript support and enhanced security, it is not fully compatible with the Node.js ecosystem, specifically with npm packages without adaptation. Developers can choose Deno for new projects but may find transitioning existing Node.js projects challenging without full compatibility.
Deno does not use a centralized package management system like npm. Instead, it directly imports modules from URLs, caching them locally after the first download. This approach aligns with web standards and allows more flexibility in sourcing modules from various providers.
Hi, folks! My name is Bartek and I'm a member of the Deno core team. Today, we're going to discuss Node.js compatibility in Deno. Can Deno run apps and libraries offered for Node.js? What are the trade-offs? How does it all work and what is next on the plate for us?
Hi, folks! My name is Bartek and I'm a member of the Deno core team. Today, we're going to discuss Node.js compatibility in Deno. In this talk, I would like to give you a quick rundown of what is Deno, and try to answer a few questions regarding compatibility with Node.
So, can Deno run apps and libraries offered for Node.js? What are the trade-offs? How does it all work and what is next on the plate for us? So, let's get right to it!
Deno one-on-one. Deno is a new command-line runtime for JavaScript and for TypeScript. It's similar to Node.js, that you can execute your JavaScript code, but the difference is that we also support TypeScript as a first-class citizen. Word of caution here, Deno doesn't actually execute your TypeScript. It just transpiles it to JavaScript underneath, behind the scenes, so you don't need to set up a build chain or anything like that. Deno also aims to be fun and productive. We like to think of it as a bag of LEGO blocks.
Deno is a single, executable file that works on Linux, Mac, and Windows. It offers secure execution by default, preventing unauthorized access to file systems and internet connections. Deno allows linking to third-party code using URLs and fetches, caches, and compiles or transpiles the code transparently. While Deno is not initially compatible with npm, some users find the lack of npm support a hurdle for adoption.
Deno is a single, executable file. This file is all you need to run any Deno program, and we will always distribute Deno as such. Deno works on Linux, it works on Mac and on Windows, so wherever you go, new server, new laptop, whatever, there's only a single command you need to execute to get Deno and you're ready to go.
Deno has something we like to call secure execution by default. What that means is none of your programs can access your file system, your environmental variables, sponsor processes, or even open an internet connection unless you explicitly allow it to. In this short example we can also see that you can directly link to third-party code and you can execute it even though you don't trust this code. So, in here we are executing an example from DenoSTD, which is Deno's standard library, it's a set of modules that are guaranteed to work with Deno, but it could have been any URL in the world you can think of, and in this case where there are no flags provided besides run sub-commands, this program cannot do anything to your computer. But if you want to access a file system or spawn a sub-process or open an internet connection, you can give Deno some flags and tell it to allow your program to actually do these things. And as you can see here some of these flags allow you to scope this even further. So for example, we can allow our program to read from the file system, however only from the slash tmp directory. Or we can tell your program to allow open an internet connection, however, only scoped to google.com domain.
Deno allows you to link to any third-party code using URLs. It works just like it does in browser. In this example we can see our es module import. We are importing a magenta function, again from Deno STD. This time we are doing this from fmt slash colors module. So this module resolution is simple and compatible with browsers and Deno has no notion of node modules or indexJS. Or actually that's what this talk is about after all. Deno doesn't depend on a centralized server. That is, you are not explicitly tied only to npm if you want to link to your packages or install new packages or a private registry if you have one. You can pull code from anywhere on the internet, either public servers or private servers if you provide proper authorization headers. Deno as a runtime fetches, caches and compiles this code, or transpiles it, transparently for you on the first run. After the first run, the code is already in cache, so there is no need to download it again. In fact, Deno won't download the code again unless you explicitly ask it to.
So, why are we even thinking or working on Node.js compatibility? Well, npm is arguably the biggest package ecosystem in the world, and users just want to use this package ecosystem. When Deno first came out with v1.0, we stated explicitly that we are not compatible with npm. And that was fine. Here, some users still find lack of support for npm a huge hurdle for adoption. So some users want to try Deno instead of Node.js. However, the cost to switch from one runtime to the other often proves too high to even try and do it.
We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career
Comments