DEV Community

loading...
Cover image for From Node to Deno

From Node to Deno

Aral Roca on May 17, 2020

Original article: https://aralroca.com/blog/from-node-to-deno Last week I published an article about Deno, and how to create a Chat app with Deno ...
pic
Editor guide
Collapse
yuripredborskiy profile image
Yuri Predborskiy

I'm afraid I'm missing something:
Deno doesn't have npm, right? So if I want a third party library, I have to go find it, grab the url, download it, and add it manually? Or use a URL, and if URL changes, I have to do the same thing again from the start?

I just don't see much point in Deno at this point, it takes one of the biggest advantages of Node, throws it out the window and declares itself the winner... and I just don't get it. From what I've read the author is proud with the fact deno has smaller and more predictable latency (from receiving request to answering request) but... handles 2/3 of node's requests per second, so we lose 1/3 of the performance for a bit of latency, and that is, like, one of the biggest advantages.

As I said, I just don't get it. If anyone can explain what is Deno supposed to replace or what problem it wants to solve, I'd be very grateful. Thanks in advance!

Collapse
dels07 profile image
Deli Soetiawan

Pika.dev, jspm, I believed someone will create something like npm later on, remember node didn't have npm from day one, like golang go mod, php composer, python pip, etc they are invented later on (even by third party developer)

Collapse
maskedman99 profile image
Rohit Prasad

Anything that gets rid of the bloated node_modules folder is a win for me.

Collapse
yuripredborskiy profile image
Yuri Predborskiy • Edited

I'm not a fan of all the bloat either, but it doesn't seem like we can change much, other than pulling all that code directly into our project and bloating the project files instead.

And then again, deno gets rid of bloated node modules folder how? By creating deno crates or something? My guess is it will be just as bloated very soon. It is a side effect from the ecosystem that relies on updateable plug-ins which use other plug-ins.

Thread Thread
quantumfillet profile image
QuantumFillet

Where would the bloat come from? Managing dependencies is as easy as creating a single typescript file with all the imports and Deno does the rest. No need to deal with node_modules. Here is a github issue discussing your grievances

Thread Thread
yuripredborskiy profile image
Yuri Predborskiy

This talks a lot about all the issues I have with deno way. Sadly, the discussion is simply closed without an answer.

Thread Thread
quantumfillet profile image
QuantumFillet

How about this reply

P.S. I'm not here to convert you to Deno xD, but if you dislike the idea of learning another technology in the already overwhelming web dev environment then I totally get where you are coming from.

Thread Thread
yuripredborskiy profile image
Yuri Predborskiy

It's actually CTCI + leetcode that take up all of my time. Including weekends.
I plan to devote some time to hobby projects down the line (including getting to know typescript, which seems to blend well with Deno), but it is not very high on my priority list at the moment.

Thread Thread
quantumfillet profile image
QuantumFillet

CTCI... oh boy.

I also have rather limited time atm, but if you want create something down the line with deno, let me know.

Collapse
quantumfillet profile image
QuantumFillet • Edited

So if I want a third party library, I have to go find it, grab the url, download it, and add it manually?

The download step is not required and I don't see how this is much different than the npm way of doing it... please eloborate.

Well if you prefer the npm and package.json way of managing modules, then yes Node will be more convenient for you - for now.

The main reason that the developers of Deno have given for the use of an import system via urls is "Furthermore the mechanism for linking to external libraries is fundamentally centralized through the NPM repository, which is not inline with the ideals of the web." (quoted from the v1 blogpost, I highly suggest the 15min read if you are struggling to see the point of deno). So essentially they are trying to avoid the whole central-source-of-trust-by-a-company thing that happened out of necessity in Node, because it was so hard to manage packages and are trying to make importing packages as easy as including javascript files in a webpage (This also means you don't have to manually install packages). After all, if you read the blogpost, the ambitions of deno are to be runtime environment like a web browser.

In my opinion the way Deno manages dependencies is also simpler and more elegant than Node, because if we compare the workflows:
Node: npm init to create project -> search for a package -> npm install it -> accidently push node_modules ^^
Deno: search for a package -> import via url -> done

But that is simply my opinion :)

Collapse
yuripredborskiy profile image
Yuri Predborskiy

I've read the blog post, I just disagree with this approach. When you have a centralized repository, you can have a more or less reliable source of information, like number of downloads and a place to search for modules. When every module is individual, without a centralized place to find them all, finding a module you want turns into an adventure with pirates, treasure hunts and fool's gold. Thanks but no thanks, in a corporate environment I want stuff that just works, period. I want to know popular repository that does exactly what I want, the way I want it to, I want it to be supported and updated and bring minimum extra dependencies. How can I know if any of this is true for a random url on the web without a centralized repository?

I prefer everything centralized which is shared in background for higher reliability and fault tolerance. In my personal opinion, npm is harder to compromise than random URL. But I may be wrong about it.

As for workflow: I initialize far too few repositories per day to make it matter. Once it is initialized, install work flow is easier for node - npm install, done. Most of the time the app is conteinerized and npm makes work flow simple. Making import statement from a fixed name is, IMO, also easier - you know for sure you are importing a validated package you installed through npm, a source you trust (I do, at least). Importing from url begs the question of audit, update (was the content replaced with a new version with breaking changes? Do I have to find the up to date version myself and manually update the link?).

This all seems counter-productive to me. Maybe deno is just not for me?

Thread Thread
quantumfillet profile image
QuantumFillet

Then I would just wait for a third party module auditer/provider like npm to arise (You will most likely still simply import via a url from a trusted domain of theirs, though).

I mean, if you are trying to get things done, then yes Node is probably better for you, because you already know it. At the moment Deno is still a young technology and doesn't have the 10 years of testing behind it's name. As the devs said in the v1 blogpost

For some applications Deno may be a good choice today, for others not yet.

I would at least give it a try in a hobby project, though, but I assume you have already done that... anyway the choice of technology is yours :)

Thread Thread
yuripredborskiy profile image
Yuri Predborskiy

I plan to try it together with typescript, they seem like a good match. I'm sure I won't be needing a lot of libraries when just starting out with TS.

Collapse
imichael profile image
✨iMichael✨ • Edited

Thanks for writing this up. Do you know if there a way to define a common host name for imports? From an aesthetic POV, this looks jarring to my eyes.

import { Client } from "https://deno.land/x/mysql/mod.ts";

It would be nice to do this instead

import { Client } from "mysql/mod";

and let some manifest or configuration flag handle the rest.

Collapse
aralroca profile image
Collapse
dels07 profile image
Deli Soetiawan

And there's might be a tool to manage this similar to npm in future

Collapse
max profile image
Maxime Lafarie

Nice post tho! 😉

Collapse
dels07 profile image
Deli Soetiawan

Like node will not replace php in past or more like rust will not replace c++ (in some area)?
I bet we will replace node when we (or big company) know what benefits and problem deno can solve, right now we don't see many benefits except for sandbox compared to node.

Collapse
wilsonuponsea profile image
Jason Wilson 🇨🇭

What happens if one of your deps loses their URL or moves things around without warning? Is there any sort of central repository or cache?
I think I‘ve seen that the import map should be used to avoid having to update an import in a bunch of files so I suppose it’s not horrible to have to fix. Just seems like a risk.

Collapse
dels07 profile image
Deli Soetiawan

Deno will cache your deps in first run so it's available offline, similar to golang did before go mod

Collapse
uzitech profile image
Tony Brix • Edited

Is there anything preventing a left-pad situation?

Collapse
muuvmuuv profile image
Marvin Heilemann

Great article!!! I really think Deno will change the JS world forever and it was about the time to refactor NodeJS. I hate that we have yarn, npm etc (big fan of pnpm btw.) and everything is centralized and controlled by a company (npm inc.). This really explains some migration very good! I would love to see more like this in future and how e.g. Node libs are included and that Deno should change our thinking of building Node applications. Especially because it has some adoption from Go/Rust world and is TypeScript by default.

PS: add github.com/alosaur/alosaur/ to the framework section, it is a pretty solid alternative to nestjs.

Collapse
craigmorten profile image
Craig Morten

Amazing article! One of the challenges with Deno atm is module discovery - it can be frustrating trying to find if an equivalent module exists!

One to consider for the list - I’ve ported Express over to Deno and Typescript in a framework called Opine github.com/asos-craigmorten/opine. It’s a port so honours the original internals and API (except where Deno deviates from Node)

Collapse
alvarezgarcia profile image
Alvarez García

Excellent compilation!.
I am starting with deno, specifically focusing on the very lightweight webview implementation (and in fact a nice way to learn internals)

Just one little thing in the webview section for the macOS users, just today the error when using directly an HTML string was fixed, wrapping the string with encodeURIComponent()

Collapse
matthewadams profile image
Matthew Adams

You say "To use Deno as a lambda, there is a module in Deno STD library. deno.land/x/lambda."

FYI, deno.land/x is NOT the standard Deno library. In fact, there was noise on the #dev deno.land Discord channel about getting rid of deno.land/x because they're against centralization.

Collapse
matthewadams profile image
Collapse
dels07 profile image
Deli Soetiawan

How about husky?

Collapse
threkk profile image
Alberto de Murga

It is impressive the amount of progress for such a young project. Congratulations to the whole community!!

Collapse
emauricio profile image
Mauricio • Edited

It would be nicer to have a more personal experience rather than linking things you can get from easy
github.com/denolib/awesome-deno examples.
in any case thank you.

Collapse
aralroca profile image
Aral Roca Author

The first article I wrote was a personal experience implementing a chat with Deno + Preact: aralroca.com/blog/learn-deno-chat-app. If It's what you are looking for.

Collapse
yanai101 profile image
yanai

thanks 😊

Collapse
cibergarri profile image
Javier Garrido

From Node to Deno:
twitter.com/deno_land/status/12625...

:D Great article!

Collapse
madhusudanbabar profile image
Krypton

Nice post

Collapse
vaviloff profile image
Vaviloff

Yaaaay, let's create a whole new ecosystem for ${this new trendy thing}!