Getting started with Deno

Conlin Durbin on April 18, 2019

In case you missed it, the new Javascript and Typescript runtime from Ryan Dahl, the creator of Node, has been released! It's got some really cool ... [Read Full]
markdown guide
 
Deno
A secure runtime for JavaScript and TypeScript 

BUT!!!

Importing from a URL
Deno lets you import from the web, just like you can in the browser. Just add a URL where you would usually name a module:
import { bgBlue, red, bold } from "https://deno.land/std/colors/mod.ts";

why? how it could be secure?!

 

Yes "Deno is safe", but that does not mean that the scripts that you will use it to execute are also.

Deno allows you to execute a nuclear bomb detonator if you wish.

But unlike Node, Deno will prevent you from lauching the bomb inadvertently.

 

It's not, not unless you can pin a hash and limit hosts in configuration.

On the flip side, I don't think it's much worse than npm.

 

It has the possibility of being much secure than Node/NPM. Even if you allow network access, a script will not have access to the file system unless you also grant it file system access. The first time you run a script, you have the option of walking through everything in all the code which requires any additional permissions (file system, network, etc) and individually granting or denying access. Eventually, the goal is to allow for more fine grained access, e.g. scoping permissions to specific paths or specific URLs.

None of this is a silver bullet, but it's much better (more secure) than Node/NPM which just allows everything.

 

It's secure because networking and other stuff are sandboxed inside a Rust sandbox, and network connection has to be explicitly granted.

 

I first heard about Deno in his famous talk.

I'm a big fan of TypeScript as well, but from what I read previously, it won't play nice with anything node explicitly, correct? But I imagine there's nothing stopping you from importing JS as that is considered valid TS.

I'm definitely curious to see where Deno goes.

 

Yeah, you should be good to just import JS - it just won't be typed. The big problem with node integration is the lack of modules. I don't think you can load an NPM package into Deno easily.

 

unless you use unpkg with ?module, in which case it's wicked-easy.

I think you could also reference a TS file from a github repo that's a TypeScript project and it'd work too maybe? I'll have to install Deno and try it out.

Deno only loads code via ES import statements (no require) using URLs or relative file paths that include the file extension. Additionally, deno does not support index.ts or index.js. So generally no drag and drop compatibility with node (though here's an example of a module that supports both deno and node: github.com/luvies/lazy). Still, probably pretty easy to create a migration script to make a project Deno compatible.

 

Hi @colin , I am React Native Developer, hoping to learn backend development with Node. Do you think Node is a good choice for beginners to start with ?

Will Deno be stable enough by 2020 to be considered production ready ? Do you think learning Node right now will not be useful as by the time I become proficient with Nodejs , Deno will be the norm ?

Apologies for the noob questions.

Thank You

 

Ryan (creator of Node and Deno) specifically addresses this question in this presentation: youtube.com/watch?v=z6JRlx5NC9E.

He says beginner developers should completely ignore Deno, that there is no guarantee Deno will still be alive in a year, and, even if Deno does exist in a year, Node will continue to exist for many, many more years to come.

 
 

No worries! Honestly, I don't know. I think there will be a lot more stability by 2020, but I don't know what the infrastructure around Deno will be. There shouldn't be too much different between Node and Deno, at least for the purpose of backend development. They are both Javascript at the end of the day. It'll just be different resources you will be using to build out backends - like the express framework for Node vs the abc framework for Deno.

Hope that helps!

 
 
 

Whoa, is that really why it's called Deno? If so, I genuinely applaud Dahl for that.

 
 

Liking it so far, very interested to see where it goes! Using deno fmt is nice too, which looks to be using Prettier.

 

I am kinda lazy and could've done it myself, but do you get autocomplete inside IDE for modules imported from URL?

 

Someone's already built a vs code extension for Deno flavor typescript: github.com/ameerthehacker/deno-vscode also github.com/justjavac/typescript-de....

Not sure if they currently support autocomplete, but, when IDEs do start supporting autocomplete for Deno modules, it'll probably be through an extension. It's also worth noting, that the recommended convention for a deno project is to only import from URL's once, in a single package.json like file called deps.ts and then re-export those modules locally from that file (example). That way you also ensure your entire project is using the same version of a module and you can change the version in a single place.

Given that Typescript itself is a node project, seems unlikely Deno will get any "official" support from the Typescript team anytime soon. That being said, one of the Deno project's goals is to provide a secure runtime for embedding javascript in larger applications. Given that Microsoft's CosmosDB database supports running javascript procedures natively (I assume through some kind of embedded VM), and given that Deno is built on Typescript (a Microsoft project), I could see Microsoft taking more/faster interest in Deno then they might ordinarily.

 

Probably not at this point, but I am honestly not sure. If it doesn't exist, I'd guess it will be added soon!

 

Excellent, I'm very excited to start. Do you know where I can find more documentation?

code of conduct - report abuse