DEV Community

Cover image for Deno Park, Getting Started With Deno
Brittney Postma
Brittney Postma

Posted on • Updated on • Originally published at console-logs.netlify.app

Deno Park, Getting Started With Deno

deno logo

TLDR: Install Deno and get going on Deno: The Complete Guide Zero to Mastery where we recreate the Space X launch data in a brand new course.

     Hello, my name is Brittney Postma and I am a self-taught developer and super mom of 3 kids. You can get started with this article and then take off to space as we recreate the Space X launch data in the brand new Deno: The Complete Guide Zero to Mastery. If you want to know more about me, you can checkout my portfolio b.Designed or my dev notes site Console Logs.

Table of Contents

What is Deno?

     Deno was created by Ryan Dahl, the same person who created NodeJS. Why would the creator jump ship to a create a whole new language? During his 2018 talk, 10 Things I Regret about Node.js, Ryan mentions some initial design decisions with Node that led to him wanting to come up with a better solution. According to the Deno site, Deno is a secure runtime for JavaScript and TypeScript. Let's break this down. Deno is built on the same engine as NodeJS, the Chrome V8 JavaScript Engine. The engine takes the code that we write and turns it into code that the computer can actually use. It was originally written in a language called Go, but was eventually replaced with Rust and Tokio due to concerns about double runtime and garbage collection. Deno is also secure by default. It has no access to outside networks or files unless explicitly enabled by using a sandbox environment. You can even use TypeScript out of the box without additional libraries. It bundles your code into a single executable file and comes with built-in utilities.

Deno vs Node.js

     Node has its own package manager, npm, and that will be the first thing you notice that is missing from Deno. Deno instead uses modules referenced as URLs, just like browsers. Deno also uses the ES Modules and does not support require(), modules are imported by import * as log from "https://deno.lan/std/log/mod.ts". This allows for Deno packages to be distributed without an additional registry to download from. Package maintainers can host their code where they want and we can use it while also automatically updating the package unless a version number is specified. There is no package.json file and no more node_modules. When the application starts, Deno will download all imported modules and cache them so they can be used offline. Once they are cached, Deno doesn't need to download them again unless we ask them to be with the --reload flag. The Deno creators recommend adding the caches of the modules to your version control system (i.e. git) in case the website the module is hosted on goes down. Importing modules by the URL can become tedious if doing so multiple times in an application. The Deno creators thought of this too and gave us an alternative. We can re-export the imported module from a file like this export { test, runTests } from "https://deno.land/std@v0.32.0/testing/mod.ts". It can then be imported by name inside the files you need them like this import { test, runTests } from './pathToFile.ts".

Will Deno replace Node.js?

     Absolutely not and will not even make a footprint in the market for quiet sometime. It is an exciting new technology that a lot of people are going to want to use, but it is too new. Node is extremely well established and supported. Deno will gain momentum and maybe some startups will pick it up along the way, but Node is still going to be around for a very, very long time.

Why Deno?

Deno is basically an improved version of Node, so why should we choose it?

  • Allows use of modern JavaScript (let, const, import)
  • TypeScript out of the box
  • URL based modules that don't need a 3rd party system.
  • No package manager to maintain, package.json, or node_modules.
  • Integrated test runner for testing your code.
  • Ability to use await at the top level.
  • Provides APIs (fetch, window object) to be as compatible with browsers as possible.

What are we waiting for, lets install Deno!

How to Install Deno

Supported shells are zsh, bash, fish, powershell, and elvish. Depending on the OS you are running and what installers you use, you are going to want to run one of these commands:

Shell (Mac, Linux):

curl -fsSL https://deno.land/x/install/install.sh | sh
Enter fullscreen mode Exit fullscreen mode

PowerShell (Windows):

iwr https://deno.land/x/install/install.ps1 -useb | iex
Enter fullscreen mode Exit fullscreen mode

Homebrew (Mac)

brew install deno
Enter fullscreen mode Exit fullscreen mode

Chocolatey (Windows):

choco install deno
Enter fullscreen mode Exit fullscreen mode

After you get the message Deno was installed successfully to /Users/username/.deno/bin/deno, you should be ready to go. The path may be different based on your machine, but you can test your installation by running deno --version to see if you get a version printed to the console. You can run deno help to see a list of commands and run deno upgrade to update your version of Deno. You should then be able to run the command deno to open the runtime environment. So, we are all set right? Not quite. If you can use the command deno right away, awesome you are ready to move on. Otherwise, we need to tell the system the correct path to Deno. If you see a message after the installation that says to Manually add the directory to your path (or similar), then you need to copy the 2 lines below it that start with export and paste and run them in the terminal. They may look similar to this:

export DENO_INSTALL="/Users/username/.deno"
export PATH="$DENO_INSTALL/bin:$PATH"
Enter fullscreen mode Exit fullscreen mode

If you run into other issues with different shells, then usually a quick Google search will take you to a Stack Overflow post with the answers you are looking for 😁.

Pick Your IDE

     Unfortunately, since Deno is so new a lot of editors will throw errors when trying to import modules because they don't natively support it. There are a few community developed extensions for a some popular editors to solve this issue. These are CoC for Vim and NeoVim, Deno plugin for JetBrains IDEs, tide and typescript-deno-plugin for Emacs, and finally, Deno for VS Code. Don't see your editor? Develop an extension or check the Discord group on how to get started.


Thanks for reading and make sure to go check out the new course over on ZTM Academy.

Top comments (8)

Collapse
 
fraybabak profile image
fraybabak • Edited

it was a greate article about deno. if you could explain more about features . it would be better. every nodejs developer has some doubts about deno . its first realase and developers and colabratores are trying to compatibale there packages with deno. for my self it is hard to update my stack rightnow. I have 4 projects running and developing it everyday with nodejs. but it has his own risk to migrate from node to deno . I think this would be blinded move. but thank you for this intro.

Collapse
 
brittneypostma profile image
Brittney Postma

I will try and update the article as I go through the course. I just wanted to get it out on launch day for the course.

Collapse
 
brittneypostma profile image
Brittney Postma

I went back through and added a couple more sections today. That may be it for this article, but I may write more on Deno in the future!

Collapse
 
trivikr profile image
Trivikram Kamat

The statement "Will Deno replace Node.js? Absolutely not and will not even make a footprint in the market for quiet sometime." is generic.

JavaScript world moves fast (as compared to other languages), and it's difficult to predict how fast deno will get adopted.
Making the time explicit (for the next couple of years) instead of generic (quiet sometime) would help improve it.

Collapse
 
opentechconsult profile image
OpenTech-Consult

I bought the course. But frankly I am will prefer Deno having his package manager or better use the NPM or Yarn package manager. I am à little disappointed. And no mention is made about performance gain and how Deno is more secure than Node

Have a good day

Collapse
 
jwp profile image
John Peters

Brittany, Thanks for excellent post.

'Npm is a poisonous snake in the grass next to a Poppy field of free software'

Collapse
 
cosminp9 profile image
Cosmin Popescu

Isn't it a bit too early for a 0-2-mastery on Deno?

Collapse
 
brittneypostma profile image
Brittney Postma

The course is going to be updated as needed with changes. Plus, it will get you all of the basics to understand the foundation for Deno and build a full scale application.