State of Deno: A Look at the Deno CLI, Node.js Compatibility and the Fresh Framework
In this State of Deno event, our panelists discussed the Deno CLI, Node.js compatibility for the npm ecosystem, and the Fresh framework.
In this wrap-up, we will take a deeper look into these latest developments and explore what is on the horizon for Deno. You can watch the full State of Deno event on the This Dot Media YouTube Channel.
Here is a complete list of the host and panelists that participated in this online event.
Hosts:
Tracy Lee, CEO, This Dot Labs, @ladyleet
Panelists:
Colin Ihrig, Software Engineer at Deno, @cjihrig
Luca Casonato, Software Engineer at Deno, @lcasdev
Bartek Iwańczuk, Software Engineer at Deno, @biwanczuk
David Sherret, Software Engineer at Deno, @DavidSherret
Table of Contents
- Exploring the Deno CLI and its features
- What is Deno?
- Built in support for TypeScript
- Built in toolchain
- Deno install and upgrade commands
- Deno permissions
- Upcoming features
- Deno products
- Deno Deploy
- Deno and Node.js compatibility
- Future support for npm packages
- The Deno to Node Transform library tool
- Fresh framework
- Conclusion
- We look forward to seeing you at our next State of Deno!
Exploring the Deno CLI and Its Features
What is Deno?
Deno is server-side runtime for JavaScript that also behaves similarly to a browser because it supports all of the same browser APIs on the server. This support provides access to existing knowledge, resources, and documentation for these browser APIs. The team at Deno works closely with browser vendors to make sure that new web APIs work well for both server-side runtime and browsers.
Built In Support for TypeScript
One of the advantages of Deno is that it ships with TypeScript by default. This removes the setup and configuration time, and reduces the barrier of entry for getting started with TypeScript. Deno also type checks your TypeScript code so you no longer have to use tsc.
Built in Toolchain
The Deno CLI comes with an entire toolchain which includes a formatter, Linter, package manager, vendor remote dependencies, editor integrations, and more. One of those tools is the Documentation Generator, which annotates library function comments, types, or interfaces with JSDocs comments to easily generate documentation. For a complete list of the Deno CLI tools, please visit their documentation page.
Deno install and upgrade commands
Deno install is another feature that allows you to take a script and install it using a global command.
`
If there is a new version of Deno, you can just run the upgrade command and it will upgrade itself, which makes it a version manager for itself.
`
Deno permissions
Deno by default will not have file, network or environment access unless you grant those permissions by running a script with command line flags.
`
Even with permissions granted, you can scope it to certain directories to allow it to only read and write in the directory of your choosing. If you run the program without permissions granted, the program will still prompt you for permission access before accessing a file.
To learn more about Deno's permissions, please read through the documentation.
Upcoming features
Deno is currently working on improving performance in the areas of HTTP, FFI (Foreign Function Interface) and Node compatibility. There are also improvements being made on the Documentation Generator, to make sure that the docs provided are good and removing the need to maintain two separate docs.
Deno Products
Deno Deploy
Deno deploy is a hosted offering that makes it easy to go from local development to production ready. This service integrates well with GitHub, and provides an option to pay only when users make requests to your services. Deno deploy has a dashboard that allows you to automate most of the processes and show you metrics, deployment statistics, CPU utilization, and network utilization. It also allows you to set up custom domains and provision certificates.
Deno and Node.js compatibility
Deno v1.15 will introduce a Node.js compatibility mode which will make it possible to run some of Node's programs in Deno. Node APIs like the http server will work in Deno as they would in Node.js. When it comes to the NPM ecosystem compatibility, the goal is to support the large number of packages built on Node.js.
The Deno team is working on these compatibility issues, because it uses web APIs for most of their operations. All of these Web APIs were created after Node.js was conceived, meaning that Node implements a whole different set of APIs to do certain operations like performing network requests. This new Node.js API compatibility layer will be able to translate API calls to modern underlying APIs which is what the actual runtime implements.
Future support for npm packages
When it comes to supporting npm packages on Deno, the goal is to have a transpiler server that takes common.js code and translates that into ESM (ECMAScript module) code. The reason for this is because, just like browsers, Deno only supports ESM code. Deno uses the concept of npm specifiers to provide access to the npm package. Deno downloads the npm package and runs it from a global cache. common.js is also supported ,and it runs the code as it is.
`
For npm packages, Deno will create a single copy of the downloaded package instead of multiple directories or sub-directories of modules. It is one global hash file, with no node_modules directory by default, and no need for a package.json by default. If a package requires a node_modules directory, then that directory can be created using a specifier flag. The following command will create a node_modules directory in the project directory, using symlink.
`
The Deno to Node Transform library tool
The Deno team built a tool to allow library authors to transform Deno packages to Node.js packages. Deno to Node Transform (DNT) takes the Deno code then builds it for Node and distributes it as an npm package. This allows library authors to take advantage of the Deno tool chain. This package can also be shipped on npm for Node.js users.
Fresh framework
Fresh is a new web framework for Deno, that makes use of the Deno toolchain ecosystem. Fresh uses JSX for templating, and it is similar to Next.js or Remix. A key difference between Fresh and Next.js or Remix, is that Fresh is built to be server-side rendered on the edge rather than server-side in a few locations. Another difference is that with Fresh, no JavaScript is shipped to the client by default, which makes it faster. Fresh handles the Server-side rendering, generates the HTML, sends the file to the client, and hydrates only the part of the page that requires JavaScript on the client by default.
Here are some products that already use the Fresh framework:
- Deno
- merch.deno.com
- Deno Deploy
To learn more about how to build apps with the Fresh framework, please read through this helpful blog post.
Conclusion
The team at Deno is making great progress to bring more exciting features to the community to make the runtime engine easy to use for building or migrating existing libraries.
If you have any questions about the State of Deno, be sure to ask here.
What is it you find exciting about Deno? We will be happy to hear about it on Twitter!
We look forward to seeing you at our next State of Deno!...