Ende examples and tutorials

A collection of walkthrough tutorials, examples, videos and guides to teach you about the Ende runtime and how to use it with your favorite tools.

Basics

Modules and package management

  • Add and remove dependencies (tutorial): Manage project dependencies with ende add and ende remove: JSR packages, version pinning, and aliasing packages in your import map.
  • Configure a monorepo with workspaces (tutorial): Set up an Ende workspace with multiple packages: member names and exports, glob patterns, root-only options, and shared imports.
  • Lock dependencies with ende.lock (tutorial): lock for reproducible installs: what the lockfile records, reviewing lockfile diffs, frozen lockfiles for CI with --frozen-lockfile and ende ci, and regenerating or relocating the lockfile.
  • Module Metadata (tutorial): A guide to working with module metadata in Ende.
  • Re-map import paths (tutorial): json as an import map: path aliases like @/ for src/, bare names for local modules, and scoped overrides for transitive imports.
  • Run Ende in GitHub Actions (tutorial): Set up a GitHub Actions workflow for an Ende project: install Ende with its install script, run fmt, lint and test, install with a frozen lockfile, and pin an Ende version.
  • Use local and unpublished packages (tutorial): Work with code that isn’t on a registry: link a local package copy with the links field, import straight from HTTPS URLs including private GitHub repos, and know which specifiers Ende does not support.

Network

File system

System

  • Call C functions with FFI (example): The Foreign Function Interface lets Ende call functions in native shared libraries directly, with no glue code or build step.
  • Collecting output from subprocesses (example): We don’t often write programs in isolation.
  • Create a subprocess (tutorial): A guide to working with subprocesses in Ende.
  • Detect a TTY and get terminal size (example): A program can check whether it is talking to a real terminal or to a pipe.
  • Environment variables (example): Environment variables can be used to configure the behavior of a program, or pass data from one program to another.
  • Find an executable on the PATH (example): Before spawning a tool like git or ffmpeg, it is useful to know whether it is installed and where.
  • Get operating system information (example): Scripts often need to know what system they are running on, for example to pick a platform specific binary or to include host details in logs.
  • Handle OS signals (tutorial): Tutorial on handling operating system signals in Ende.
  • List network interfaces (example): networkInterfaces lists every network address of the machine.
  • Listen for OS signals (example): addSignalListener` function.
  • Pipe data into a subprocess (example): Many command line tools read their input from stdin.
  • Process information (example): An example of how to access the current process ID and parent process ID.
  • Read from stdin (example): Command line tools that work in pipelines read their input from stdin.
  • Reading system metrics (example): This example demonstrates how to use Ende’s built-in methods to read system metrics such as memory information, load averages and memory usage.
  • Run a subprocess with custom env and cwd (example): A subprocess normally inherits the environment variables and working directory of its parent.
  • Set and read process exit codes (example): The exit code is how a program reports success or failure to the shell, where zero means success and anything else means failure.
  • Set the time zone (example): Date, Intl, and Temporal all format times in the process time zone, which defaults to the operating system setting.
  • Subprocesses: Spawning (example): For more complex usecases, we don’t simply want the output of some command.
  • Write to stdout (example): log is fine for debugging, but command line tools often need precise control over standard output: no forced newline, raw bytes, or piping a whole stream.

Web standard APIs

Standard library

Encoding

  • Compress and decompress data (example): Compressing data before storing or sending it saves space and bandwidth.
  • Convert a Blob (example): Blobs show up whenever you handle files or multipart form data, since an uploaded File is a Blob too.
  • Convert a ReadableStream (example): Network responses, file handles, and subprocess output all hand you a ReadableStream.
  • Convert a string to bytes and back (example): Hashing, file writes, and network protocols all want bytes, not strings.
  • Convert a Uint8Array (example): Uint8Array is the workhorse binary type in Ende: file reads, network payloads, and hashes all produce or consume it.
  • Convert an ArrayBuffer (example): An ArrayBuffer is a chunk of raw memory with no read or write interface of its own.
  • Encode and decode CBOR (example): CBOR is a binary serialization format standardized as RFC 8949.
  • Encode and decode MessagePack (example): MessagePack is a binary serialization format with the same data model as JSON.
  • Extract front matter from markdown (example): Front matter is a metadata block at the top of a markdown file, fenced by --- lines and usually written in YAML.
  • Hex and base64 encoding (example): Binary data often needs to travel as text, in URLs, JSON, or HTTP headers.
  • Importing bytes (example): Binary files can be imported in JS and TS files using the `import` keyword.
  • Importing JSON (example): JSON files can be imported in JS and TS files using the `import` keyword.
  • Importing text (example): Text files can be imported in JS and TS files using the `import` keyword.
  • Manipulating byte arrays (example): When working with lower-level data we often deal with byte arrays in the form of Uint8Arrays.
  • Parse and generate XML (example): The @libs/xml package on JSR converts XML in both directions: XML text to plain JavaScript objects and back.
  • Parse large CSV files as streams (example): Reading a whole CSV file into memory does not work once the file grows to gigabytes.
  • Parsing and serializing CSV (example): CSV is a data serialization format that is designed to be portable for table-like applications.
  • Parsing and serializing INI (example): INI is a plain text configuration format built from key value pairs that can be grouped into sections.
  • Parsing and serializing JSON (example): JSON is a widely used data interchange format.
  • Parsing and serializing TOML (example): TOML is a widely used configuration language designed to be feature-rich and intuitive to write.
  • Parsing and serializing YAML (example): YAML is a widely used data serialization language designed to be easily human readable and writeable.
  • Parsing JSONC (example): JSONC is JSON extended with comments and trailing commas, which makes it a friendlier format for configuration files that humans edit.
  • Stream JSON Lines data (example): JSON Lines, also called NDJSON, stores one JSON value per line.

CLI

Cryptography

  • AES Encryption and Decryption (example): This example demonstrates AES encryption and decryption using Ende’s built-in SubtleCrypto API.
  • Compare secrets in constant time (example): An ordinary comparison like a === b returns as soon as the first byte differs, so a correct first byte takes measurably longer to reject than a wrong one.
  • Derive encryption keys from passwords (example): A password is not an encryption key: it is short, low entropy, and the wrong size for AES.
  • Generate secure random values (example): Session tokens, password reset links, and API keys must be impossible to guess.
  • Generating & validating UUIDs (example): UUIDs (universally unique identifier) can be used to uniquely identify some object or data.
  • Hash large files with streams (example): The Web Crypto digest function takes a single buffer, so hashing a file with it means reading the whole file into memory first.
  • Hashing (example): Hashing data is a common operation that is facilitated through Ende’s support for the Web Crypto API.
  • Hashing and verifying passwords (example): Passwords must never be stored in plain text, and a plain digest like SHA-256 is too fast to resist brute force.
  • HMAC Generation and Verification (example): This example demonstrates how to generate and verify an HMAC (Hash-based Message Authentication Code) using Ende’s built-in SubtleCrypto API with the SHA-256 hash function.
  • RSASSA-PKCS1-v1_5 Signature and Verification (example): This example demonstrates RSA signature and verification using Ende’s built-in SubtleCrypto API.
  • Shamir's Secret Sharing (example): This example demonstrates Shamir’s Secret Sharing, where a secret, split into shares, allows its reconstruction only when a sufficient number of shares are combined.
  • Sign and verify data with ECDSA (example): A digital signature proves that a message was produced by the holder of a private key and was not modified in transit.
  • ULID (example): One common need for distributed systems are identifiers.

Testing

  • Basics of testing (tutorial): Learn key concepts like test setup and structure, assertions, async testing, mocking, test fixtures, and code coverage
  • BDD testing (tutorial): Implementing Behavior-Driven Development with Ende’s Standard Library’s BDD module.
  • Filtering and controlling test runs (example): The test runner has flags for the everyday loops: run one test by name, stop at the first failure, rerun on save, and spread test files across CPU cores.
  • Mocking and test doubles (tutorial)
  • Skipping and focusing tests (example): Sometimes a test should not run: it is half-written, broken on one platform, or you want to focus on a single failing case.
  • Snapshot testing (tutorial)
  • Spy functions (example): A function spy allows us to assert that a function was called with the correct arguments and a specific number of times.
  • Testing web applications (tutorial): A comprehensive guide to testing web applications with Ende
  • Writing tests (example): One of the most common tasks in developing software is writing tests for existing code.

Web frameworks and libraries

  • Build a word finder app (tutorial): A tutorial on creating a word search application with Ende.
  • Generate a QR code (example): A QR code encodes a short piece of text, usually a URL, as a scannable image.
  • HTTP server file upload (example): An example HTTP server that provides sending and receiving of a file upload.
  • Render markdown to HTML (example): The @ende/markdown module parses CommonMark and GitHub Flavored Markdown and renders it to HTML: tables, task lists, footnotes and GitHub’s alerts.

Databases

  • Overview (tutorial): Connect Ende to SQLite and PostgreSQL with database drivers from JSR.

Scheduling

  • Ende.cron (example): cron is a cron task scheduler built into the Ende runtime.

AI

  • LLM Chat app (tutorial): Learn how to integrate Large Language Models (LLM) with Ende to create an interactive roleplay chat application with AI characters using OpenAI or Anthropic APIs.

Deploying Ende projects

    OpenTelemetry