CEOInterviews.AI
Start App
Get an email when Ryan Dahl gives a new interview
One email per new interview. Unsubscribe in one click.
Ryan Dahl
Co-founder, Deno (now part of Cloudflare), Cloudflare

Deno 2 • Ryan Dahl • GOTO 2024

📅 Dec 20, 2024 GOTO Conferences 41 MIN 8840 VIEWS 20 SEGMENTS · 2 SPEAKERS
This presentation was recorded at GOTO Chicago 2024. #GOTOcon #GOTOchgo https://gotochgo.com Ryan Dahl - Creator of Node.js JavaScript Runtime as well as the Deno JavaScript/TypeScript Runtime ‪@ryandahl1554‬ ‪@deno_land‬ RESOURCES https://bsky.app/profile/tinyclouds.org https://github.com/ry https://github.com/denoland   / deno_land   https://tinyclouds.org Links https://deno.com https://deno.com/2 https://jsr.io ABSTRACT Deno is a modern toolchain for JavaScript and TypeScript that eliminates setup hassles by bundling essential tools like a linter, formatter, test runner, type checker,...

Questions asked in this interview

1
  1. 39:58What would you say is the biggest barrier to adoption of Deno 2 or Deno in general right now?
Ryan Dahl 0:12 ↗
Hello, good morning. What's up, everybody? Very nice to be in Chicago, and this is actually my first time here.
I'm going to talk a bit about Deno. So I'm best known for creating Node. I think it's software that is used a lot. Raise your hand if you have used Node.js. Okay, yeah, as expected.
Essentially every website uses Node in some way or another, if not actually served from Node.js, it is used in the front-end tooling. You know, maybe you're bundling your JavaScript with webpack. It is a cornerstone of the modern web, and yeah, it was very exciting to work on Node.
I continue to work on JavaScript runtimes. For the past couple of years, I have been working on a project called Deno, which is also a runtime for JavaScript. It is a more modern flavor of this, and just two weeks ago we released Deno 2 after many, many years of development. Deno 1 was released in 2020, and yeah, I'm going to talk a bit about Deno 2 today, give you some demos, play around. Maybe I'll hit some bugs and everything will come crashing down, or the Wi-Fi won't work. We'll see. Live demos are always exciting, but before I get to live demos...
Yeah, it's worth explaining why I continue to work on JavaScript runtimes after, you know, 15 years now. And I think this stat from GitHub, GitHub survey 2023, shows the languages ordered by the number of repositories that they're used in, and in first place since they started doing this is JavaScript. It is the world's most popular programming language, and in third place there is actually TypeScript, which is also JavaScript. It's just JavaScript with types, and in between there is squeezed Python. But suffice it to say that JavaScript is something like the default programming language. It is the cornerstone of the web. It is a protocol of the web, like HTTP, like CSS, like HTML, and that makes it quite different than other languages. Obviously, Python is not going away anytime soon, but JavaScript is really rooted, human infrastructure is really rooted in these web protocols. And I think it's safe to say that five years from now you're still going to be using HTML, you're still going to be using HTTP, and you'll still be using JavaScript. There's not, you know, in technology it's pretty hard to look out five years and make concrete statements that everybody can agree with, and I think five years is putting it lightly. Likely JavaScript will be here 10 years from now, if not much, much longer. And because of that, it is incumbent on us to create a good foundation for executing this default programming language. And frankly, what I did with Node, you know, 15 years ago, is insufficient in my mind for the main way that people are going to be programming in the future.
Deno is similar to Node in that it executes JavaScript, but it's really much more than that. So it does have native TypeScript support built into it, both for execution and for type checking. It is built on web standards, and a big part of why I got into this was to narrow the gap between Node and browsers. It's just inconceivable to me that, you know, 10 years after ES modules were specced out, that people are still using CommonJS, that until recently Node did not have a fetch method in it. The future of JavaScript will always be browser JavaScript, and so although server-side JavaScript does different things, you know, it creates HTTP servers, it's important to continually re-evaluate and, as the language evolves and new APIs are added, to narrow the gap between browsers and server-side JavaScript.
Deno is an all-in-one toolchain. I'll demonstrate that, but it's literally a single-file executable that has everything you need to get started and do JavaScript development. And it has some nice secure properties, some security properties, and it's backwards compatible with Node. And I'm going to stop rambling about this and just show you what it's like to program in Deno. And I'm going to do it with a little bit of a contrived example here. I'm going to make kind of an ls program, just to kind of kick the tires on the system and get a sense of what this Deno thing looks like. So, is this visible to you? Great.
All right, so let's commence the failure-prone live demos here. So I'll call this program tree, and I'm just going to start off by touching a main.ts file, and let's just open up VS Code and get started here. So here's my blank file, and what I want to do is let's read the current directory and output it to the console. Okay, so you can do that with an API called Deno.readDir, and as you notice, as I'm typing, I'm getting kind of nice documentation in line with VS Code. This is because Deno has a language server, and it interacts with VS Code and provides IntelliSense and all sorts of niceties kind of out of the box. And let's just readDir the current directory and see what that gives us. This thing returns an async iterable, so we can just do a for-await loop at the top level and kind of loop over the async iterable that comes out of this thing. So we'll just console.log entry here, and let me open up the terminal. So here's our program, right? It's kind of doing ls on the current directory, and let's see. So when I run this, it doesn't immediately work. It gives me a permission prompt, and this is hitting Deno's secure-by-default feature. So we don't allow you to access the file system by default, we don't allow you to access the network by default, we don't allow you to do anything by default. In fact, we're trying to utilize the JavaScript VM, V8's secure sandbox, and by default you have no access to any operating system stuff. You have to allow it. So this is analogous to in the web browser when you might have a website that accesses a webcam, it might ask for your permission to do that. You don't get access to the webcam by default, right? You're running untrusted code all the time in the web browser, you just can't allow it to do anything it wants. Similarly in Deno. So in order to give it access here, we have to say, yes, let's give readDir access to read the current directory, and it outputs this little object that has, you know, some properties about the only thing in this directory, which is the main.ts file. So yeah, maybe we can say name instead of that, instead of the entry object, and if we add an allow-read, then we can bypass this whole permission prompt business and just get our main.ts file here. Let's... this allow-read, by the way, has kind of a nice shorthand, which is capital R, so you don't actually have to click through the permission prompts every time. Let's kind of abstract this example a little bit into a function. So let's say we want to have a function called tree which takes a dir as a string, and let's say that it just returns an array of strings, and we'll just move all this stuff up into here. And let's modify this a little bit. So we'll create an out array here, and instead of console logging, we'll... oops, we'll do out.push(entry.name), and then we'll return out. Sorry, this is getting a little cramped here. So I'm getting a little squiggly line here. This await is underlined. Anybody know what I'm missing here? Yeah, so this async iterable needs an async function. So the language server again is helping me out here, and yeah, I added an async here, and I'm getting another red squiggly. That's because I'm not returning a promise, right? Async functions have to return a promise. So let me fix up that one. And actually, you know, before I do that, you can, you know, we're interacting with the TypeScript language server through this VS Code plugin that I have, this Deno VS Code plugin, but you can do type checking similarly on the command line, like in CI, by just running deno check main.ts, and that will also give you kind of the TypeScript errors if you need that in CI. That's saying the same thing that this little red squiggly is giving me up here. So yeah, anyway, let's turn that into a promise.
And let's call this function. So tree, and I'm going to choose a directory that's slightly more interesting than this current one. ry/src/deno_runtime, this is some source directory that is in the Deno project, just as an example. So await tree, and let's say that returns some files, and then I can console.log files. Does that work? Let's try it. So I'll run that, and yeah, indeed I get some... oh, that's not the... that's the current directory still. Okay, what am I missing? I'm missing this dir is orange underlined, and that's because it's not being used here. I haven't actually replaced this string here with dir. That's actually the Deno linter running in the background. And you know, maybe to make that a little bit more concrete, if I just run deno lint, it will also tell me about that unused variable, that unused argument dir. All of this stuff kind of comes for free in Deno. You don't need to configure your ESLint, you don't need to configure your tsc, you don't need to configure Prettier. It's auto-formatting my code too. You know, if I put in some wackiness in here, it's going to auto-format that back to something slightly reasonable. And the nice thing about this is that you can give this deno.exe to any new developer who might not be familiar with Node, right? They might not know that you need to use ESLint for linting, they might not know how to configure Prettier, they might not know how to configure TypeScript. The idea with Deno is that when we're using a scripting language, things should be easy. Like, why are you using a scripting language in the first place, right? If you want programming to be really hard, go use Rust, go use C++. You'll get something better out of it, you'll get a faster program at the end of the day. If you're using a scripting language, what you're doing is optimizing for developer time. And by bundling everything into the Deno executable, by having kind of sane defaults and zero configuration, we allow the developer to essentially bypass all of this boilerplate configuration that happens at the start of Node projects.
Okay, let me keep going here. So what were we doing? We were console logging this thing. And is that the end of my demo? Maybe. Okay, let's go back to the slides. So yeah, you can, you know, in Node you might just do node file.js, in Deno you do deno file.js. In Node you might use tsc to type check your TypeScript code, in Deno you can just use deno check. You might use npm install in Node to create a node_modules directory to get all of the things from your package.json and download those dependencies. In Deno you can run deno install, I'll show that in a second, and there are other subcommands for essentially any behavior that you want here. I want to look at one of these in a little bit more detail, deno compile down here. Let's try to deno compile this little ls program, this little tree program that I'm doing. deno compile allows you to take a TypeScript file, a TypeScript program, a JavaScript program, and output a binary executable. So let's see that in action. So here's my main.ts, actually let me go over to my VS Code here. So I've been running deno run main.ts, if I just stick in a compile here, it is going to output a new file called tree that is an ARM64 Macintosh executable here that I can now do tree and it will read the current directory. Oh, I forgot to fix my bug from before. I've got to go over here, replace the unused variable with dir, and let's try it again. Oh, I have to recompile, of course. There we go. So this tree function, this tree executable now, you saw that I changed the source, the main.ts file, it does not depend on the main.ts anymore. This is like a completely self-contained executable that has no dependencies. Actually, there are some shared libraries that load system sort of things, but not a big problem. Let's kind of take this a little bit further and add cross-compiling into this target. So if you give a target option, you can actually cross-compile for different platforms. And let's say I wanted a Windows executable of this ls program, all I would do is give the target x86_64-pc-windows-msvc, and now I have this tree.exe which I cannot run because I don't have a Windows computer, but believe me that this thing actually is the ls program now in Windows. So yeah, that's all there is to deno compile. The idea is that all of this stuff should feel very easy and simple here.
So most of those things you could do in Deno 1 already. Let's talk about what's new in Deno 2. Deno 2 is a revamp in three main areas: ecosystem compatibility, particularly with the npm ecosystem, package management, and various enterprise features that we kind of learned about from talking to companies. So Deno originally was pretty disjoint from the Node/npm ecosystem, and that has changed pretty radically over the last couple of years. And now with Deno 2, most npm packages are supported, and we strive to support all of them. There is of course a long tail of things that might not work, but very complex modules like gRPC or packages that are using native extensions, so-called N-API, are supported in Deno. So yeah, Deno really understands package.json and node modules and works well with the npm ecosystem. Let's see this, just to demonstrate this maybe with a different example. I want to do npx create-next-app just to create a Next.js app here, and let me do whatever test123 to not conflict with my other directories, and let's just run this default Next.js app. And hopefully the internet is fast enough to download some stuff. This is running, this is using Node, npx is using npm which uses Node, and doing an npm install here. And if we wait a second, we get a test123 directory with your normal Next.js setup, and of course you have your node_modules folder with like amazingly 300 megabytes of dependencies. Next.js is not the smallest thing on earth. And what you can do now, of course, in your package.json that it creates for you, it has some scripts here that can be run, right? The Next.js development server, and Deno understands all of this stuff. So if I do deno task, I can run these various scripts here. So I could do deno task dev, and that will start the Next.js development server. And of course I can, you know, maybe edit some page here. Maybe we'll edit getting started by editing just say Deno and see that that works. Yes, it does, hot module reloading, etc. All of this running under Deno, of course. You can actually even run that create-next-app program in Deno itself, and I will try to attempt that right now. npm create-next-app, here I'm giving it -a because create-next-app is going to do a bunch of wacky stuff, it's going to create a bunch of files, it's going to need all sorts of permissions, so I'm just going to bypass this setup and bypass all permissions coming from Deno and run this create-next-app thing. So that is the create-next-app now running in Deno. create-next-app forks out to npm install to actually do this node_modules installation, and yeah, let's come back to that in a second.
Slideshow. So yeah, Deno programs can import npm packages using a package.json like we just saw in the Next.js app, or they can actually do this without any package.json at all. Deno excels at single-file scripts. In fact, this was kind of the original impetus that we were working with. By the way, how's my time here? I want to be a little wary of it. Oh, I'm good. Okay. So yeah, let's show pulling in an npm package in this ls program that I'm working here. So let's say my little tree program needs color output, right? Let's pull in an npm library that can give us some color output here. So I'm just going to import chalk. Do you know chalk? Chalk is a library that gives you colored output, and I can just do import chalk from npm:chalk. Just need that npm: here. Note I do not have a package.json, I have no node_modules folder, all I've got is that chalk, and I'm going to do chalk, let's say green background, and this files thing I'm just going to join it with a new line so that it's not an array. So now I can do deno run main.ts. Weirdly, I'm getting a permission prompt here for an environment variable FORCE_COLOR. Chalk, who knew, but it reads a bunch of environment variables. So it reads FORCE_COLOR, TERM, and of course Deno doesn't allow you by default to just access these things. So you know, as you're using npm packages, you can actually kind of see what they're trying to do with your system. And so yeah, let's just allow all of those. And if we click yes to all of those environment accesses, then indeed we get some green output here at the bottom. We can of course bypass all the permission prompts by adding allow-env, or just shorthand is -e. So yeah, chalk requires reading permissions. That is one way of reading permissions in... or sorry, one way of outputting color in Deno. There's a web standard way of outputting color text to the terminal. Does anybody know about this? No? %c. This works in the browser. Chalk does not work in the browser, but let's see this. If I comment out this chalk npm thing, let's actually do the web standard version of this. You can actually do a %c, and then I'm just going to append this files thing. Is that making sense to you? And then let's just do color, yeah, yellow, let's say, just so we can see a different color here. That CSS there as the second argument is actually something that you can do in Chrome. And yeah, now I have yellow output, and importantly now I don't need the allow-env flag because we're not using chalk anymore, so we don't need the extra permission, so we can kind of get it down to be smaller. But yeah, the main point is that pulling in npm dependencies is just a single line of code, and your programs, if they are simple, can scale down to small files.
So yeah, in Deno 2 you can run existing Node applications in Deno, you know, pretty much without caveat, except caveat, sometimes, most of the time it works. Deno understands package.json and node_modules out of the box, and if you're not using package.json or node_modules, Deno can allow you to pull in essentially any npm library just with a single line of code, and the security prompts still apply, right? There's no configuration, nothing to set up. We've also improved this package management situation. I mentioned earlier deno install is similar to npm install, and yeah, we also have deno add, deno remove, these are for adding and removing dependencies as you imagine from npm install, npm add, and npm remove. So yeah, let me, this is my create-next-app here, and just to demonstrate what deno install does, it's pretty obvious what it does, but just to make this super clear, let me delete that node_modules folder and run deno install now. And now I have a new node_modules here, and of course that was my installation, and of course I can still run my Next.js app as normal. So that's what deno install does. Again, all of this hopefully feels very familiar to you and is not very surprising.
This setup with node_modules and package.json, this is nice because a lot of times we do have to interact with npm modules, but if this was all there was to package management, it would be a little bit disappointing. We are really trying to level up JavaScript here, and we have introduced earlier this year a new registry for publishing TypeScript code, JavaScript code to, that is similar to npm in many ways. It is a registry where you can share code. It does support TypeScript natively, it does enforce ECMAScript modules, you cannot publish CommonJS to this. It is designed to work with npm, we don't expect npm to ever go away, but what I mean by that is that JSR modules can depend on npm modules, so in a way it's a superset of npm, and it is made for all runtimes, right? We live in a world where the Node package manager, I think, is not sufficient, because there is Cloudflare Workers, and there is Bun, and there is Deno, and there are browsers, right? We really need a registry for all JavaScript users. So yeah, let me show you JSR a little bit. Let me put it this way: post-GitHub acquisition, npm has stopped evolving. npm is a closed-source piece of software that has been acquired by GitHub and then Microsoft, and is, yeah, it doesn't make money, it's not a product for them, right? It's just something that they keep running, which is nice, it's reliable, I'm glad that Microsoft is running npm, but how frustrating is it to publish packages to npm? How, you know, how is it to take some TypeScript code and decide what targets you're going to compile to? Like, it's, I'm not sure how many of you have dealt with this problem, but it can be a real head-scratcher, even for people who are very used to working in the JavaScript space. JSR makes this dead simple, and let me demonstrate this.
So let's see, I'm just going to go to JSR. So jsr.io is the website, and you can log in here, and I'm just going to click publish a package. I'm going to publish it under my scope, I'm going to call this package tree, and I'm going to click the create button. What it does is it gives me a little JavaScript JSON file that I can drop into my project. You can call it jsr.json or deno.json, either one works. So let me go over to my VS Code here, and let me create a deno.json and paste in this project here, and let me just delete these other files, deno.exe, and the thing I need to modify here is that I don't have a mod.ts, I have a main.ts, and rm tree, sorry, almost deleted the Deno executable. Okay, there we go. And yeah, let's just keep following the instructions here. It says deno publish. So you can do all of this from Node. I'm showing all of this from Deno, of course, because this is a Deno talk, but you can use JSR from Node, and you can use npx jsr publish, but I'm going to use, oops, keep going back to this one, I'm going to use deno publish here. And I get a little error, and the error is that I'm missing a license field here. So let me add that. It does require me to put a license. If you care, this will be MIT licensed, and then you can use this. So yeah, I have to authorize this publishing, and I click yes. JSR has some nice security attributes that I won't talk about, and now I've published this package. That was all there was to it, right? No compiling your TypeScript. And this actually gives you autogenerated documentation, and I'm looking here and I'm realizing that I have not exported any symbols. I am a bad package author. So let me actually go back here and export my tree function. And I'm just realizing that I don't want to have this stuff in my, for everybody who imports this package, so let me actually gate that import.meta. If this is the main file, skip this or do this, but if it's imported as a package, then I don't need this. Okay, so I'm going to republish this. I just have to bump the version now, of course. I've published a bad one. Approve it again, wait a second, and yeah, now I have my tree function here, and this is kind of the autogenerated documentation for this tree function. JSR has a great lot of nice features, including autogenerated documentation. I cannot believe npm does not have autogenerated documentation in the year 2024 for the default programming language. It's kind of insane, but that is why we are building JSR. So yeah, I'll leave it at that to check out JSR, but suffice it to say that it improves the lives of consumers, it really improves the lives of publishers, and this is a completely open-source project that we intend to be community-managed. This is not a commercial product or anything.
You might, if you've looked at Deno before, you might know that we have a lot of URLs in our dependencies. This has changed quite radically in 2.0. You can still pull in modules from URLs, but we do encourage people to use dependencies on JSR or npm because they tend to scale better. I won't go into that in great detail right now, but I've got a blog post that, you know, if you feel like reading for 45 minutes, you can go read my blog post on JSR. We have also published the Deno standard library and made it available for all runtimes. Most of these packages are stabilized at version 1.0 now, and just to demo that a little bit, let me go over here and pull up the standard file system library. Here it is, and there's a function in here called walk, and this function recursively walks over a directory. And the way that you import it is just with this little snippet of code right here. So let me improve my demo now a little bit by going back over to my walk and change this readDir into a walk. So now it's going to recursively walk over subdirectories. So if I run this again, we should get more entries. And maybe we do, maybe we don't, it's a little hard to see because I'm not outputting the full path here. So let me change that entry.name to an entry.path. And yeah, we're going into subdirectories now and kind of seeing all sorts of files here. So let me just make this a little bit nicer with a relative import here. Sorry, import a function called relative from node built-in library node:path. All of the node built-in modules are available in Deno now, and so let's pull in this relative function and make it relative to the dir that we're walking over, just so we have kind of a nice directory of stuff. But I'm getting an error right now, hold on a second, I think maybe I need to do dir, comma, entry.path, hopefully. And this is the problem with live demos, so you're going to hit some problem. Okay, there we go. So now we have it kind of as relative paths here. So let's see here, how am I doing on time? Great. I will publish this and skip to a slightly more interesting piece. So I'm going to publish my relative path thing and do deno publish, and I'm getting an error now because I am importing the standard fs, but I have not given it a version. Let me just give it an @1 there and republish. That should work. Okay, we've now published our tree function, which actually does a recursive walk, does not return an async iterable, but an array of items.
And I am going to skip my talk about some of these enterprise features. I'll just note that long-term support is coming to Deno, and there are a bunch of other interesting features, but I really want to show you one more thing, which is Jupyter notebooks are well integrated into Deno, and I'm going to just open up my terminal here and go into my tree directory, cd temp tree, and let me just run this Jupyter notebook program. Do you guys know Jupyter notebooks? Yes, usually for Python. No longer now for JavaScript and TypeScript. I'm going to create a new notebook, and I'm just going to change the kernel from Python to Deno. Deno has full support for this, and now I can type, you know, x equals 1 plus 2, and I should be able to evaluate JavaScript here. So I'm going to import a little helper library here. I'm going to import two things: document, I won't tell you what that is, and a little function called penguins. Penguins, do I have that spelled right? From jsr, jupyter helper, j helper, oops, slash ry. Okay, great. So penguins, penguins is an async function that loads a little data set, which is what I need in order to show you some pretty plots here. So I'm going to just assign this data set to a variable p, and penguins has a bunch of data about penguins of all things, but I want to show you Observable Plot in Deno, and Observable Plot is made by Mike Bostock, the guy who makes D3, and you can pull this in from npm, observablehq/plot. So that's pulling in the Observable Plot library, and what we can do is plot, we're going to plot some penguins here, marks, and we'll say plot.dot for a scatter plot, and we'll use that p variable. I just have to do two records to put in kind of the right shape here, and we're going to do kind of a scatter plot of two of these columns here, culmen length, whatever that is, and let's say culmen depth. These are some random penguin measurements, apparently. And I have to add this document thing that I'm not going to tell you about, but if I do that... cannot read property of undefined, reading plot, import star as plot, there we go. Okay, so now I've got a scatter plot of some penguins, and yeah, that's all it takes to pull in a little npm library here. So yeah, just trying to give you a sense of what it's like to work in Deno. There's a whole blog post about this and some videos that you can watch, but yeah, maybe I have a second for one question or so.
Yeah, so we've got time for probably a couple questions. Anybody in the crowd want to start us off? Cedric?

2 more exchanges in this transcript

Sign in free to read the rest of this interview. No card required.

Sign in to read the full transcript

Cite this transcript

APA, MLA, BibTeX
APA

Dahl, R. (2024, December 20). Deno 2 • Ryan Dahl • GOTO 2024 [Interview transcript]. GOTO Conferences. CEOInterviews.AI. https://ceointerviews.ai/interview/3274155/

MLA

Ryan Dahl. "Deno 2 • Ryan Dahl • GOTO 2024." GOTO Conferences, 20 Dec. 2024. Transcript, CEOInterviews.AI, https://ceointerviews.ai/interview/3274155/.

BibTeX
@misc{dahl2024_3274155,
  author       = {Ryan Dahl},
  title        = {Deno 2 • Ryan Dahl • GOTO 2024},
  howpublished = {Interview transcript, GOTO Conferences. CEOInterviews.AI},
  year         = {2024},
  month        = {dec},
  url          = {https://ceointerviews.ai/interview/3274155/},
  note         = {Speaker-attributed transcript with timestamps}
}