Beginner's Guide to Deno

i'm trav
- i work at universal music
- head of forking at crablang
- streaming bad code live on twitch
- terrible takes @techsavvytravvy
- find me in the crablang lounge on discord
i've also been known to make music
Search for a command to run...

i'm trav
i've also been known to make music
No comments yet. Be the first to comment.
In this series, I will be going over the basics of popular and emerging technologies.
If you're new to GraphQL, you might be wondering what all the fuss is about. GraphQL is a query language for APIs that allows developers to request data in a more efficient way. In this article, we'll take a look at what GraphQL is, how it works, and...
I've always been intrigued by browser extensions and their ability to do crazy things and make the web cooler + get rid of ads. That said, going from concept to a working Chrome extension can be super annoying with repetitive setup tasks, configurati...

This is going to be a "quick" little guide to customizing the tmux status bar to include a scrolling Spotify “Now Playing” widget. I’m going to be doing this on macOS, but you should be able to adapt it to Linux and I'll try to assist where I can. If...

Go From Freelancer to Corporate Sellout In 43 Easy Steps

An overview of one of the most popular and loved programming languages.

The Importance of Mental Health as a Developer

So you want to learn about Deno, the new JavaScript runtime? Well, you've come to the right place! This guide will teach you everything you need to know about Deno.
Deno is a runtime for JavaScript, TypeScript, and WebAssembly that is based on the V8 JavaScript engine and the Rust programming language. It was created by Ryan Dahl, the original creator of Node.js, to remedy some the regrets he had when making Node.
Here are a few reasons why you might want to use Deno:
Secure by default. This means that it uses a sandbox to prevent code execution from outside the Deno process, and all network and file system operations are sandboxed by default.
Built-in support for TypeScript.
Ships with a set of standard libraries, which are written in TypeScript and are located in the Deno namespace. This means that you don't have to install third-party libraries to use Deno.
A plugin system that allows you to import third-party libraries as plugins. This means that you can import only the functionality that you need, and the plugin is sandboxed and can't access the Deno process.
A built-in test runner, which makes it easy to write and run tests for your Deno applications.
Open source and released under the MIT License.
Now that you know a little bit about Deno, let's get started!
First, you need to install Deno. The easiest way to do this is in with curl:
curl -fsSL https://deno.land/x/install/install.sh | sh
If you're on Mac, you can install Deno with a package manager like Homebrew.
brew install deno
Now that you have Deno installed, you can run Deno programs with the deno command.
deno run https://deno.land/std/examples/cat.ts
This will fetch and run the cat.ts program from the Deno Standard Library. The Deno Standard Library contains a collection of reusable Deno programs.
Now that you know how to run Deno programs, let's write our own! Create a file called hello.ts and add the following code to it:
console.log("Hello, world!");
You can run this program with the deno command:
deno run hello.ts
You should see the output Hello, world!.
That's it! You've written your first Deno program!
Now that you know the basics of Deno, let's dive a bit deeper. In this section, we'll learn about some of the more advanced concepts in Deno.
In Deno, there are two ways to structure your code: scripts and modules.
Scripts are simple programs that are run with the deno command. Modules are program modules that can be imported by other programs.
Let's see an example of each.
First, let's create a script. Create a file called script.ts and add the following code to it:
console.log("This is a script.");
You can run this script with the deno command:
deno run script.ts
Next, let's create a module. Create a file called module.ts and add the following code to it:
export function hello() {
console.log("Hello, world!");
}
This module exports a single function called hello. We can import this function into another program and call it.
Create a file called main.ts and add the following code to it:
import { hello } from "./module.ts";
hello();
This program imports the hello function from the module.ts module and calls it.
You can run this program with the deno command:
deno run main.ts
You should see the output Hello, world!.
In Deno, libraries are collections of modules that are bundled together. Libraries can be published to Deno's Registry so that they can be easily reused by others.
Let's see an example of how to use a library. We're going to use the gravatar library to generate Gravatar URLs.
Create a file called main.ts and add the following code to it:
import { gravatar } from "https://deno.land/x/gravatar/mod.ts";
console.log(gravatar("example@example.com"));
This program imports the gravatar function from the gravatar library and calls it with the email address example@example.com.
You can run this program with the deno command:
deno run main.ts
You should see the output https://www.gravatar.com/avatar/00000000000000000000000000000000?d=mp&s=80.
You should now have a good understanding of Deno and be able to start writing your own programs. For more information, check out the Deno documentation.
Let me know in the comments if this was helpful or if you have any questions.
Be sure to follow me for more like this!