Deno 1.38: env support, API changes, and new features
In November, everyone’s favorite TypeScript runtime got a fresh new version! As usual, let’s cover what you can expect from Deno 1.38.
HTML Documentation#
Deno has a really interesting command called deno doc, which does exactly what you’d expect—it generates documentation for the module you’re reading.
Until now we had a few options like generating the documentation as JSON, or only generating the private module documentation, but that wasn’t very useful, especially since most of them were just a way to print the same documentation in the terminal.
Now, version 1.38 includes an --html option that lets you generate full documentation pages for your module even if it’s not published on deno.land.
Just run:
deno doc --html --name "My module" ./mod.tsAnd it’ll generate a series of HTML documentation files that you can publish. You can do this for ANY module and any file in your project.
This is the video created by the Deno team showing how it can be done.
Plus, the new --lint option makes Deno analyze your code for problems that could hurt your documentation!
Hot Module Reload#
One of the most interesting features of Deno is being able to use the excellent --watch when running code to reload your application if something changes.
The problem is that often this app restart doesn’t happen as expected, interrupting processes mid-execution. That’s why we now have an improvement with the --unstable-hmr option.
HMR (or Hot Module Reload) is a technique widely used in development, especially for frontend work, to replace the contents of a file without restarting the entire process, keeping state, memory, and everything that comes with it.
This video from the Deno team shows how well this feature helps with development:Notice that as the increment number changes, the application already picks up the result and starts applying the new change without needing to restart the entire app.
You can also pass specific files to this flag with:
deno run --unstable-hmr=data.ts ./mod.tsAnd you can also listen to HMR update events using an event listener:
addEventListener('hmr', (e) => { console.log(e.detail.path)}).env Support#
Like Node did before, now it’s Deno’s turn to have native support for .env files. That’s unexpected, since Deno already has support through its standard library for the dotenv module, but now you can use it directly from the command line.
Imagine you have a .env file at your project root. To run this file directly, you can pass the --env option to deno run:
deno run --env main.tsYou can also specify the file:
deno run --env=.env.dev mod.tsOther changes#
- You can now use any package manager (
yarn,pnpm) to download NPM modules - Behind the
--unstable-bare-node-builtinsflag you can now use Node modules without thenode:prefix - Faster JSX compilation and transformation
deno tasknow supports theheadcommand on all platforms- The VSCode extension for Deno now supports the standard options for JavaScript and TypeScript from the code editor itself
- The extension now has a sidebar with all the tasks from your
deno.jsonfile - You can now use
Deno.testin the REPL - You can use
usingwith some classes from theDenonamespace like:FsFile,FsWatcher,HttpConn,HttpServer,KvandListener
FTS Time!#
If you liked this article, I also have a complete TypeScript course called TypeScript Formation!
I invite you to check it out if you want to learn more about TypeScript with me and our amazing community with hundreds of students!