Based on post.

Install module

$ deno install https://deno.land/std/examples/welcome.ts

The script will be downloaded to the cache and an executable will be added as a stub as below.

  • ~/.deno/bin/welcome
      #!/bin/sh
      # generated by deno install
      deno "run" "https://deno.land/std/examples/welcome.ts" "$@"
    

It can be run directly like this:

$ ~/.deno/bin/welcome
Welcome to Deno 🦕

If the bin directory is in your PATH you can just run:

$ welcome
Welcome to Deno 🦕

Remote code is fetched and cached on first execution, and never updated until the code is run with the --reload flag. (So, this will still work on an airplane.)

Upgrade Deno

$ deno upgrade

Upgrade to a target version.

$ deno upgrade --version 1.2.0

The std packages get installed when you change versions. If you get errors, you can reload the cache for your application.

$ demo cache --reload my_app.ts

Run

Run local script

Run a script in your project. Use -A to allow all permissions.

$ deno run index.ts

Download and run module

This module will be downloaded from the Deno packages the first time and on subsequent runs it will run quicker as it is already installed in bin.

$ deno run https://deno.land/std/examples/welcome.ts
Welcome to Deno 🦕

If you installed it with deno install URL or with the run command above, it will be stored and can be run directly:

$ ~/.deno/bin/welcome

Open console

Start Deno in interactive mode.

$ deno

Or

$ deno repl

Development

Bundle

Bundle a script.

$ deno bundle https://deno.land/std/examples/echo_server.ts server.bundle.js
Bundling https://deno.land/std/examples/echo_server.ts
Emitting bundle to "server.bundle.js"
2.61 KB emitted.

Run it.

$ deno run --allow-net server.bundle.js
Listening on 0.0.0.0:8080

Format

$ deno fmt index.ts
$ deno fmt --check PATH

Lint

$ deno lint PATH

Test

  • test.ts
      import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
    
      Deno.test("deno test", () => {
          const name = "Foo";
          const surname = "Bar";
          const fullname = `${name} ${surname}`;
          assertEquals(fullname, "Foo Bar");
      });
    
$ deno test test.ts

Assertions

  • equal
  • assert
  • assertEquals
  • assertStrictEq
  • assertStrContains
  • assertMatch
  • assertArrayContains
  • assertThrows
  • assertThrowsAsync
  • unimplemented
  • unreachable

Debugging

Browser

Allow browser dev tools debugging by using a flag.

$ deno --inspect
  • --inspect flag allows attaching a debugger at any point in time,
  • inspect-brk will wait for debugger breakpoint and pause execution on the first line of code.

VS Code

  • settings.json
      {
          "version": "0.2.0",
          "configurations": [
              {
              "name": "Deno",
              "type": "node",
              "request": "launch",
              "cwd": "${workspaceFolder}",
              "runtimeExecutable": "deno",
              "runtimeArgs": ["run", "--inspect-brk", "-A", "index.ts"],
              "port": 9229
              }
          ]
      }