new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Deno · Fundamentals · all subjects

configuration

113 notes in this subject, read out of this brain and free to use. This is page 2 of 2.

Override OpenTelemetry endpoints for metrics, traces, and logs

Endpoints can be individually overridden using: OTEL_EXPORTER_OTLP_METRICS_ENDPOINT, OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, OTEL_EXPORTER_OTLP_LOGS_ENDPOINT.

Configure OpenTelemetry exporter authentication headers

If the OTLP endpoint requires authentication, headers can be configured using the OTEL_EXPORTER_OTLP_HEADERS environment variable.

OpenTelemetry span status codes

Span status is set using span.setStatus() with a status object containing code and message. Available status codes from SpanStatusCode: OK (unset status), ERROR.

Example: Create and end a span with error handling in OpenTelemetry

function myFunction() { return tracer.startActiveSpan("myFunction", (span) => { try { // do myFunction's work } catch (error) { span.recordException(error); span.setStatus({ code: trace.SpanStatusCode.ERROR, message: (error as Error).message, }); throw error; } finally { span.end(); } }); } This example shows how to create an active span, record exceptions, set error status, and ensure the span ends in a finally block.

Example: Create a counter and record values in OpenTelemetry

import { metrics } from "npm:@opentelemetry/api@1"; const meter = metrics.getMeter("my-app", "1.0.0"); const counter = meter.createCounter("my_counter", { description: "A simple counter", unit: "1", }); counter.add(1); counter.add(2); counter.add(1, { color: "red" }); counter.add(2, { color: "blue" }); This example shows how to create a meter, create a counter instrument, and record values with optional attributes.

Example: Extract and inject context with propagation in OpenTelemetry

import { context, propagation } from "npm:@opentelemetry/api@1"; function extractContextFromHeaders(headers: Headers) { const ctx = context.active(); return propagation.extract(ctx, headers); } function injectContextIntoHeaders(headers: Headers) { const ctx = context.active(); propagation.inject(ctx, headers); return headers; } async function tracedFetch(url: string) { const headers = new Headers(); injectContextIntoHeaders(headers); return await fetch(url, { headers }); } This example shows how to extract context from incoming headers and inject context into outgoing headers for distributed tracing.

Example: Run function in new context with OpenTelemetry

import { context } from "npm:@opentelemetry/api@1"; const currentContext = context.active(); const newContext = currentContext.setValue("id", 1); context.with(newContext, () => { console.log(context.active().getValue("id")); // 1 function myFunction() { return context.active().getValue("id"); } console.log(myFunction()); // 1 setTimeout(() => { console.log(context.active().getValue("id")); // 1 }, 10); }); console.log(context.active().getValue("id")); // undefined This example shows how to create a new context with a value and run functions within that context, including asynchronous callbacks.

Native TypeScript compiler (tsgo) integration with unstable flag

TypeScript's native compiler written in Go, typically around 10 times faster than the JavaScript `tsc`, is integrated into Deno behind an unstable flag. Enable it with the `DENO_UNSTABLE_TSGO=1` environment variable or the `--unstable-tsgo` flag for a single command, or add `"unstable": ["tsgo"]` in `deno.json` for the whole project.

Native TypeScript compiler (tsgo) is unstable and preview

The native compiler integration is an unstable, preview feature that is not yet feature-complete. Some programs that type-check with the default compiler may report different results. Do not rely on it for CI or release builds yet. Report issues at https://github.com/denoland/deno/issues.

Configure TypeScript compiler options in deno.json or tsconfig.json

TypeScript compiler options can be set under `compilerOptions` in either `deno.json` or `tsconfig.json`. For Deno-first projects, keeping them in `deno.json` means one config file instead of two.

Deno auto-detects tsconfig.json and jsconfig.json

Each workspace directory is probed for a `tsconfig.json`; if one exists, Deno automatically uses it for type checking and the language server with no flags needed. Since Deno 2.1, `jsconfig.json` is also auto-detected when a `package.json` is present, which is useful for JavaScript-only projects.

deno.json compilerOptions take precedence over tsconfig.json

If a `deno.json` with `compilerOptions` is present, those take precedence over `compilerOptions` in `tsconfig.json`. Emit-related options in `tsconfig.json` are ignored with a warning, since Deno does not write output files.

Enable JavaScript type-checking project-wide with checkJs

Enable `compilerOptions.checkJs` in `deno.json` to turn on type-checking for all JavaScript files project-wide, without adding `// @ts-check` to each file.

Configure lib property for targeting browsers and web workers

Use `compilerOptions.lib` to change which type libraries Deno type-checks against. By default, Deno uses `deno.window` which does not include browser globals. To include browser globals, add `"lib": ["dom", "dom.iterable", "dom.asynciterable", "deno.ns"]` to keep the Deno namespace available. For web workers, use `lib: ["deno.worker"]` or a `/// <reference lib="deno.worker" />` directive.

Alternative: use .d.ts file with triple-slash directive for global augmentation

Instead of inline `declare global`, put augmentations in a `.d.ts` file and load it via a triple-slash directive (`/// <reference types="./global.d.ts" />`) or globally in `deno.json` under `compilerOptions.types`.

Deno built-in TypeScript support without additional configuration

Deno has built-in TypeScript support, allowing you to write TypeScript code without additional configuration or tooling.

Update Deno to latest or specific version

To update Deno, run 'deno upgrade' to fetch the latest release from github.com/denoland/deno/releases, unzip it, and replace the current executable. Use 'deno upgrade --version 2.7.0' to install a specific version.

Deno is a single binary with no external dependencies

Deno is a single binary executable with no external dependencies. It runs on macOS, Linux, and Windows, on both x64 and arm64 architectures.

Windows minimum version requirement for Deno

Deno requires Windows 10 version 1709 or later, or Windows Server 2016 version 1709 and up, due to requiring IsWow64Process2.

Default Deno binary installation paths

When installed via the shell or PowerShell script, the deno binary is placed at $HOME/.deno/bin/deno on macOS and Linux, and %USERPROFILE%\.deno\bin\deno.exe on Windows. The install directory can be overridden by setting the DENO_INSTALL environment variable before running the install script.

Deno cache directory default locations

Downloaded dependencies and compiled artifacts are stored in Deno's cache directory. The default locations are: Linux: $HOME/.cache/deno, macOS: $HOME/Library/Caches/deno, Windows: %LOCALAPPDATA%\deno. This can be overridden by setting the DENO_DIR environment variable.

Manual installation of Deno from releases

Deno binaries can be manually installed by downloading a zip file from github.com/denoland/deno/releases. Each release ships one archive per platform containing a single executable. Assets available: Windows x86_64 (deno-x86_64-pc-windows-msvc.zip), Windows ARM64 (deno-aarch64-pc-windows-msvc.zip), macOS ARM64/Apple Silicon (deno-aarch64-apple-darwin.zip), macOS x86_64/Intel (deno-x86_64-apple-darwin.zip), Linux x86_64 (deno-x86_64-unknown-linux-gnu.zip), Linux ARM64 (deno-aarch64-unknown-linux-gnu.zip). After unzipping, place the deno executable on your PATH and set the executable bit on macOS and Linux. Each asset has a matching .sha256sum file for verification.

npm installation performance note for Deno

The startup time of the Deno command gets affected if it is installed via npm. The official install script (shell or PowerShell) is recommended for better performance.

Linux distribution packages lag behind latest Deno release

Deno does not publish an official apt repository. Versions packaged by Linux distributions such as Debian, Ubuntu, Arch, or the Snap Store are community maintained and often lag behind the latest release. For the most up-to-date version on any Linux distribution, use the shell installer or manual download, which always installs the current release.

Uninstall Deno installed via shell or PowerShell script

To uninstall Deno installed via shell or PowerShell script: first run 'deno clean' to clear the cache directory ($DENO_DIR), then remove the installation directory (rm -rf ~/.deno on macOS/Linux, or Remove-Item -Recurse -Force $env:USERPROFILE\.deno on Windows). Finally, remove the line sourcing Deno's env file from your shell config (~/.bashrc, ~/.zshrc, ~/.profile, etc.) — the line looks like '. "$HOME/.deno/env"'. Fish users should additionally remove ~/.config/fish/conf.d/deno.fish.

zsh Deno completions setup

Install zsh Deno completions by creating ~/.zsh directory, running deno completions zsh > ~/.zsh/_deno, then adding to ~/.zshrc: fpath=(~/.zsh $fpath), autoload -Uz compinit, and compinit -u. If completions don't load after reloading the shell, remove ~/.zcompdump/ and run compinit again.

VSCode Deno setup with Deno: Initialize Workspace Configuration

To set up Deno in Visual Studio Code, install the Deno extension by Denoland from the Extensions tab, then open the Command Palette with Ctrl+Shift+P and select 'Deno: Initialize Workspace Configuration'. This creates a .vscode/settings.json file with {"deno.enable": true} which enables IntelliSense, code formatting, linting, and LSP features.

JetBrains IDE Deno setup

To configure Deno in JetBrains IDEs, install the official Deno plugin from File > Settings > Plugins. Then go to File > Settings > Languages & Frameworks > JavaScript Runtime and switch Preferred Runtime to Deno. Specify the path to the Deno executable if it has not been auto-detected.

Neovim 0.11+ Deno setup with nvim-lspconfig

For Neovim 0.11 or later, use the built-in language server client with nvim-lspconfig which has a ready-made Deno configuration. If also using ts_ls (TypeScript language server), configure denols with root_markers = { "deno.json", "deno.jsonc" } and ts_ls with root_markers = { "package.json" } and workspace_required = true to prevent both servers from attaching to the same buffer.

Helix editor Deno language server configuration

Configure Deno in Helix by editing languages.toml to set roots = ["deno.json", "deno.jsonc", "package.json"] for both typescript and javascript language blocks, then add a [language-server.deno-lsp] section with command = "deno", args = ["lsp"], and config.deno.enable = true.

Sublime Text Deno LSP client configuration

Configure Deno in Sublime Text via the LSP package by adding to .sublime-project: a "deno" client under LSP settings with command ["deno", "lsp"], enabled true, selector "source.ts | source.tsx | source.js | source.jsx", and initializationOptions with enable and lint keys.

Emacs eglot Deno LSP configuration

Configure Deno in Emacs using eglot by adding ((js-mode typescript-mode) . (eglot-deno "deno" "lsp")) to eglot-server-programs and defining an eglot-deno class. The eglot-initialization-options method can set enable, unstable, and typescript inlayHints options.

Deno shell completion command and supported shells

Generate shell completions using deno completions <shell> which outputs to stdout. Supported shells are: bash, elvish, fish, powershell, and zsh. Pass the --dynamic flag to generate project-aware completions that suggest task names from deno.json when typing deno task <TAB>.

bash Deno completions setup

Install bash Deno completions by running: deno completions bash > /usr/local/etc/bash_completion.d/deno.bash, then source the file with: source /usr/local/etc/bash_completion.d/deno.bash

fish Deno completions setup

Install fish Deno completions by running: deno completions fish > ~/.config/fish/completions/deno.fish

PowerShell Deno completions setup

Install PowerShell Deno completions by running: deno completions powershell >> $profile, then source with: .$profile. This creates a PowerShell profile at $HOME\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 that runs on every PowerShell launch.

Plain --watch unaffected by atomic save

Plain --watch mode is not affected by atomic save issues in editors, because each change triggers a full restart that re-establishes the watchers.

Atomic save editors break --watch-hmr file watcher

Some editors use atomic save (also called safe write), where the editor writes changes to a temporary file and then renames it over the original on each save. On Linux this replaces the file with a new one on disk, which can detach the file watcher used by --watch-hmr after the first change. The symptom is that hot replacement works once and then stops detecting further edits to that module.

Disable atomic save in editors for --watch-hmr compatibility

To work around atomic save issues with --watch-hmr, disable atomic save in your editor. In Helix, set [editor] atomic-save = false (it is enabled by default). In Neovim/Vim, set :set backupcopy=yes.

Watch mode examples

Examples of using watch mode: deno run --watch main.ts, deno test --watch, and deno fmt --watch. Example of excluding files: deno run --watch --watch-exclude=file1.ts,file2.ts main.ts. Example of excluding glob pattern: deno run --watch --watch-exclude='*.js' main.ts. Example of hot module replacement: deno run --watch-hmr main.ts or deno watch main.ts.

--watch flag enables file watcher

The --watch flag can be supplied to deno run, deno test, and deno fmt to enable the built-in file watcher. The watcher enables automatic reloading of the application whenever changes are detected in the source files. This is useful during development to see the effects of changes immediately without manually restarting the application.

Watch mode file inclusion by subcommand

For deno run and deno test, the entrypoint and all local files that the entrypoint statically imports will be watched. For deno fmt, all local files and directories specified as command line arguments are watched, or the working directory if no specific files or directories are passed.

--watch-exclude flag syntax

You can exclude paths or patterns from watching by providing the --watch-exclude flag with the syntax --watch-exclude=path1,path2. Multiple paths or patterns are separated by commas. When excluding glob patterns, surround them in quotes to prevent shell expansion, for example --watch-exclude='*.js'.

--watch-hmr flag for hot module replacement

The --watch-hmr flag is supported by deno run and hot-replaces changed modules in the running process instead of restarting it. This keeps the application's state across edits. If hot replacement fails, the process falls back to a full restart.

deno watch shorthand command

deno watch is a shorthand command for deno run --watch-hmr.

Evaluate code with deno eval and deno repl

Use `deno eval "console.log(Deno.version)"` to evaluate a code expression inline, or use `deno repl` to open an interactive REPL for experimentation.

Project tasks example in deno.json

Example deno.json configuration with tasks: {"tasks": {"dev": "deno run --watch --allow-net main.ts", "start": "deno run --allow-net main.ts"}}. Run with `deno task dev` or `deno task start`.

Run a TypeScript or JavaScript file

Use `deno run main.ts` to execute TypeScript or JavaScript files. The `run` keyword can be omitted and Deno will figure it out: `deno main.ts` is equivalent to `deno run main.ts`.

Script arguments passed after script name in Deno.args

Arguments for the script go after the script name and are passed through in `Deno.args`. Example: `deno run main.ts arg1 arg2 arg3` results in `Deno.args` containing `["arg1", "arg2", "arg3"]`.

Runtime flags must come before script name

Runtime flags like `--allow-net` must appear before the script name. Anything passed after the script name is treated as a script argument, not a Deno runtime flag. For example, `deno run --allow-net net_client.ts` is correct, but `deno run net_client.ts --allow-net` is incorrect and will pass `--allow-net` to the script's arguments instead.

Run code from URL or stdin

Deno can run code directly from a URL or from stdin. Use `deno run https://example.com/script.ts` to run from a URL, or `echo 'console.log(1 + 1)' | deno run -` to run from stdin. Remote code is sandboxed like everything else and gets no permissions unless explicitly granted.

Watch mode with --watch flag

Use `deno run --watch main.ts` to automatically rerun the program whenever a file it depends on changes. The `--watch` flag also works with `deno test`, `deno fmt`, and other commands.

Define and run project tasks with deno task

Define repeatable commands in a `deno.json` file under a `tasks` field and run them with `deno task <taskname>`. This is the Deno equivalent of `npm run`. Tasks can run other tasks, set environment variables, and work cross-platform.

Give your agent this brain