How to Install Deno on macOS

How to Install Deno on macOS

Deno is a simple, modern and secure runtime for JavaScript and TypeScript, by the creator of Node.js himself, Ryan Dahl. Deno uses the Chrome v8 engine and is built with Rust. The project just reach version 1.0 and got many people in the JavaScript community interested.

In this tutorial I will show you how we can install Deno for macOS in a matter of seconds using Curl.

1. Use Curl in your terminal to install Deno

curl -fsSL https://deno.land/x/install/install.sh | sh

A successful response should give you further details on how we can configure your bash or zsh profile.

Deno was installed successfully to /Users/username/.deno/bin/deno
Manually add the directory to your $HOME/.zshrc (or similar)
  export DENO_INSTALL="/Users/username/.deno"
  export PATH="$DENO_INSTALL/bin:$PATH"
Run '/Users/username/.deno/bin/deno --help' to get started

2. Manually add the directory to your $HOME/.zshrc or $HOME/.bash_profile

locate the $HOME/.zshrc or $HOME/.bash_profile (depending on what you use) file and add the following lines in the file. Make sure to use the correct information provided in the terminal after a successful install.

#deno
export DENO_INSTALL="/Users/username/.deno"
export PATH="$DENO_INSTALL/bin:$PATH"

3. Verify that everything was installed an configured correctly

We can verify that everything was installed and configured correctly by running the deno welcome.ts test project.

deno run https://deno.land/std/examples/welcome.ts

☝️ Notice If you get zsh: command not found: deno or similar error, restart your terminal or open a new tab and run the command once again, so that the changes to your bash or szh profile can take effect.

Download https://deno.land/std/examples/welcome.ts
Warning Implicitly using master branch https://deno.land/std/examples/welcome.ts
Compile https://deno.land/std/examples/welcome.ts
Welcome to Deno 🦕

4. Create an example project & server

create a new project folder and add a main.ts file

import { serve } from "https://deno.land/std@0.55.0/http/server.ts";
const s = serve({ port: 8000 });
console.log("http://localhost:8000/");
for await (const req of s) {
  req.respond({ body: "Hello World\n" });
}

Then run the project with a --allow-read and --allow-net flag

deno run --allow-read --allow-net main.ts

Deno should start downloading dependencies, compiling the project, starting the server and console logging the localhost address.

Download https://deno.land/std@0.55.0/http/server.ts
Download https://deno.land/std@0.55.0/encoding/utf8.ts
Download https://deno.land/std@0.55.0/io/bufio.ts
Download https://deno.land/std@0.55.0/testing/asserts.ts
Download https://deno.land/std@0.55.0/async/mod.ts
Download https://deno.land/std@0.55.0/http/_io.ts
Download https://deno.land/std@0.55.0/io/util.ts
Download https://deno.land/std@0.55.0/textproto/mod.ts
Download https://deno.land/std@0.55.0/http/http_status.ts
Download https://deno.land/std@0.55.0/async/deferred.ts
Download https://deno.land/std@0.55.0/async/delay.ts
Download https://deno.land/std@0.55.0/async/mux_async_iterator.ts
Download https://deno.land/std@0.55.0/fmt/colors.ts
Download https://deno.land/std@0.55.0/testing/diff.ts
Download https://deno.land/std@0.55.0/path/mod.ts
Download https://deno.land/std@0.55.0/bytes/mod.ts
Download https://deno.land/std@0.55.0/path/_constants.ts
Download https://deno.land/std@0.55.0/path/win32.ts
Download https://deno.land/std@0.55.0/path/posix.ts
Download https://deno.land/std@0.55.0/path/common.ts
Download https://deno.land/std@0.55.0/path/separator.ts
Download https://deno.land/std@0.55.0/path/_interface.ts
Download https://deno.land/std@0.55.0/path/glob.ts
Download https://deno.land/std@0.55.0/path/_util.ts
Download https://deno.land/std@0.55.0/path/_globrex.ts
Compile file:///Users/username/deno/deno-test/main.ts
http://localhost:8000/

Your Deno application is now up and running, you can visit your localhost address (http://localhost:8000/) and be greeted with the Hello World.

Freddie Freddie 3 years ago 0
Login to Comment
No comments have been posted yet, be the first one to comment.
Enable & Write Cron Jobs for Strapi
Enable & Write Cron Jobs for Strapi
A cron job is a useful utility that can be found in any unix-like operating system. It can be used to schedule time-based commands without human intervention. With Strapi, we can use cron jobs to import data or run application tasks automatically. To write cron jobs in Strapi is super...
Create, Access and Use SSH Keys with macOS
Create, Access and Use SSH Keys with macOS
SSH or "Secure Shell" is a network protocol for operating networked services securely. It is typically used for remote command-line authentication and command execution. In this tutorial I will show you how you can create, access and use your SSH key for macOS. 1. Open Termi...
How to Install Redis on MacOS with Curl
How to Install Redis on MacOS with Curl
Redis a fantastic free and open-source in-memory key-value database that can be used to cache your web app to improve both performance and resource consumption. Today I will go over how we can install and run Redis locally on your Mac. Installing Redis for macOS is not as straight for...