And if I ran that, of course, that whoops, I wouldn't want to use the compiled version. I'm just going to Deno run and then I'll do dash dash, allow net to allow network access specifically. And then that's going to basically do the same thing. But one thing you'll notice right away is that this import uses the file extension. And in Deno, we tried to make the Deno runtime, you know, as closely as we can to browser behavior. The only globals except for the Deno global that are in a Deno application, you know, are globals that you would have in the browser. So there's, you know, fetch and a lot of the other browser based globals are available in Deno. And the way that you specify imports is usually by specifying, you know, a fully qualified URL. And, but no, it doesn't actually work in the same way.
In a Node project, you'll usually will, you know, import, you know, external files without a, without a specifier. So let's do the same thing. We'll create a new file called, you know, handler.js. And here we'll have to actually do something slightly different. So in Node, if I'm going to create an ESM module, you know, I would call it MJS. And I guess, since we're running it in Deno now, I don't have to do that. So I'll just leave it as a .js extension. And I'll do kind of the same thing. I'm going to, you know, export default. And then I will essentially make this the same handler that we would have over here. So it'll just be an async, you know, fat arrow function. So it's going to do about the same thing. And then over here, I could say, you know, import handler from .slash handler. But again, in Node project, I'm probably going to just say .slash handler, which is the, you know, which is generally the convention in Node. You don't use the, you know, the extension when you're trying to import. We can actually configure Deno to handle this, again, by using one of those unstable flags. So if we go to Deno.json, this one is called what, David? It's like sloppy imports, like with a hyphen. So we'll say sloppy imports. And if we enable that and go back to index.js, you can see the red squiggly has sort of downgraded to a blue squiggly because, you know, we're not using the extension. But other than like web standards, why else, like, don't we use that in Deno generally, David? Like what's the cost of not having the extension? Yeah. So when you don't have the extension, then it needs to do a lot of probing.
Comments