DEV Community

Cover image for Getting started with Deno

Getting started with Deno

Conlin Durbin on April 18, 2019

Edit: Deno has hit 1.0 and with it, there has been some major discussion around whether the project needs an explicit CoC. The original maintainer...
Collapse
 
stamper profile image
Alexander Toropov
Deno
A secure runtime for JavaScript and TypeScript 
Enter fullscreen mode Exit fullscreen mode

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";
Enter fullscreen mode Exit fullscreen mode

why? how it could be secure?!

Collapse
 
fvilante profile image
Flavio Vilante

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.

Collapse
 
chromadream profile image
Jonathan Nicholas

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

Collapse
 
sqlrob profile image
Robert Myers

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.

Collapse
 
johncarroll profile image
John Carroll • Edited

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.

Collapse
 
nickytonline profile image
Nick Taylor • Edited

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.

Collapse
 
wuz profile image
Conlin Durbin

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.

Collapse
 
bennypowers profile image
Benny Powers 🇮🇱🇨🇦

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

Thread Thread
 
nickytonline profile image
Nick Taylor

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.

Thread Thread
 
johncarroll profile image
John Carroll • Edited

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.

Collapse
 
devhammed profile image
Hammed Oyedele

Awesome, do you know? "De-No" - "No-De".

Collapse
 
somedood profile image
Basti Ortiz

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

Collapse
 
devhammed profile image
Hammed Oyedele

Just saying, but it can be the reason.

Thread Thread
 
somedood profile image
Basti Ortiz

Oh. 😅 Still funny nonetheless.

Collapse
 
reactnativeguy profile image
Sudeepto Dutta

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

Collapse
 
wuz profile image
Conlin Durbin

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!

Collapse
 
reactnativeguy profile image
Sudeepto Dutta

Thanks for the input Conlin 🙂

Collapse
 
johncarroll profile image
John Carroll • Edited

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.

Collapse
 
reactnativeguy profile image
Sudeepto Dutta

Thanks for the input John 🙂

Collapse
 
elanandkumar profile image
Anand Kumar • Edited

Looks like this article need to be updated. To run the file, we have to use deno run FILENAME.
And seems the color package is missing now at the url used in the example

Collapse
 
kamranayub profile image
Kamran Ayub

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

Collapse
 
realabbas profile image
Ali Abbas

Hail Ryan, Deno is the future. 🖖

Collapse
 
codehexz profile image
CodeHexz

Great Article, But I was looking for a practical application of Deno and looking to get started with Deno and develop a REST API for my application. So I found a step-by-step guide here for developing a simple API using Deno, TypeScript & Oak Framework.

Collapse
 
antoninbeaufort profile image
antoninbeaufort

Hey, the import link has changed, the good now is https://deno.land/std/fmt/mod.ts

Collapse
 
aexol profile image
Artur Czemiel

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

Collapse
 
johncarroll profile image
John Carroll • Edited

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.

Collapse
 
wuz profile image
Conlin Durbin

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

Collapse
 
fabianmendoza profile image
FabianMendoza

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