Code Samples

Runnable examples for Elide's runtime and toolchain

These examples use only the elide command. Run them in an empty directory.

Run TypeScript

// discount.ts
interface Order {
  price: number;
  quantity: number;
}

const order: Order = { price: 79.99, quantity: 2 };
console.log(`$${(order.price * order.quantity).toFixed(2)}`);
elide run discount.ts
$159.98

Format Java and Kotlin

elide format routes .java files to Google Java Format and .kt or .kts files to ktfmt. Paths and formatter flags follow --.

elide format -- src
elide format --list-files -- --dry-run src

The first command rewrites files in place. The second changes nothing and exits with code 1 if any file needs formatting.

Call JavaScript from Python

from elide import js

total = js("[1, 2, 3, 4].reduce((a, b) => a + b, 0)")
print(total)
elide python interop.py
10

Use the embedded SQLite module

import { Database } from "elide:sqlite";

const db = new Database();
db.exec("CREATE TABLE users (name TEXT)");
db.exec("INSERT INTO users VALUES ('Ada')");
console.log(db.query("SELECT name FROM users").get().name);
elide run database.ts
Ada

Install an npm package

Given a package.json with dependencies:

elide install --ecosystems=npm
elide run main.ts

npm packages are installed under .dev/dependencies/npm and exposed through a project node_modules link. Maven dependencies use a project-local repository under .dev/dependencies/m2.

Serve static files

elide serve --no-tui ./public

The static server listens on 127.0.0.1:8080 by default. Use elide dev --no-tui ./public for file watching and live reload on port 3000.

See CLI Reference for command syntax and Elide Projects for build configuration.