DEV Community

Manthan Ankolekar
Manthan Ankolekar

Posted on

Deno Cheatsheet

Deno is a runtime for JavaScript and TypeScript that is built on the V8 JavaScript engine. It is designed to be secure, simple, and reliable. Here's a cheat sheet to help you get started with Deno:

Installation

Using Shell (Linux/macOS):

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

Using PowerShell (Windows):

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

Using Chocolatey (Windows):

choco install deno
Enter fullscreen mode Exit fullscreen mode

Basic Commands

  • deno run : Run a TypeScript or JavaScript file.
  • deno eval "console.log('Hello, Deno!')": Execute JavaScript/TypeScript code directly.
  • deno info : Display information about the TypeScript/JavaScript file.
  • deno repl: Start an interactive REPL (Read-Eval-Print Loop).

Permissions

Deno has a permission-based model for accessing resources. When you run a script, it may need certain permissions to perform actions like accessing the file system or network. Use the --allow-* flags to grant permissions.

  • --allow-read: Read access to files and directories.
  • --allow-write: Write access to files and directories.
  • --allow-net: Network access.
  • --allow-env: Access to environment variables.
  • --allow-run: Execute other programs.

Example:

deno run --allow-read myscript.ts
Enter fullscreen mode Exit fullscreen mode

Package Management

Deno uses ES modules for importing dependencies. You can import modules directly from URLs or use a package manager like deno.land/x.

Dependency Locking

  • Generate a lock.json file: deno cache --lock=lock.json --lock-write deps.ts
  • Use the lock.json file to ensure reproducible builds: deno cache --lock=lock.json

Third-Party Tools

Deno has several third-party tools and libraries available:

TypeScript Support

Deno has excellent TypeScript support by default. You can use TypeScript features like type checking and interfaces seamlessly.

Deno CLI Flags

  • --allow-all: Grants all permissions (use with caution).
  • --unstable: Enables unstable APIs.

Upgrade Deno

To upgrade Deno to the latest version, you can use the following command:

deno upgrade
Enter fullscreen mode Exit fullscreen mode

This cheat sheet covers the basics of Deno. For more in-depth information and documentation, please visit the official Deno website: https://deno.land/

Top comments (0)