Skip to content

JavaScript and TypeScript with Elide

Run your first TypeScript program, install and import an npm dependency, and test it with node:test; no compile step or tsconfig.json.

On this page

Elide runs JavaScript and TypeScript directly, with CommonJS, ES modules, and a subset of the Node and Web APIs. This quickstart builds a small greeting program, adds an npm dependency, and tests the greeting.

Bringing an existing app? Start with Elide for Node users and the framework compatibility table.

Install

Install Elide, open a new terminal, then check:

Terminal
bash
elide --version

If the command is not found, follow Verify the install.

Run a file

TypeScript runs as written

No compile step and no tsconfig.json: elide app.ts runs the file.

Terminal
bash
mkdir hello-elide
cd hello-elide

Save this as app.ts:

ts
const name: string = "Ada";
console.log(`Hello, ${name}!`);
utf-8 · ts · Lines: 2
Terminal
bash
elide run app.ts
Hello, Ada!

You can also use elide app.ts. For JavaScript, remove : string and save the file as app.js.

Running a TypeScript file directly with Elide
 ~/demo  bat greet.ts
───────┬────────────────────────────────────────────────────────────────────────────────────────────
       │ File: greet.ts
       │ Size: 253 B
───────┼────────────────────────────────────────────────────────────────────────────────────────────
   1   │ interface User {
   2   │   id: number;
   3   │   name: string;
   4   │ }
   5   │ 
   6   │ const greet = (user: User): string => `Hello, ${user.name}!`;
   7   │ 
   8   │ const users: User[] = [
   9   │   { id: 1, name: "Ada" },
  10   │   { id: 2, name: "Linus" },
  11   │ ];
  12   │ 
  13   │ for (const user of users) {
  14   │   console.log(greet(user));
  15   │ }
───────┴────────────────────────────────────────────────────────────────────────────────────────────
 ~/demo  elide ./greet.ts
Hello, Ada!
Hello, Linus!
 

npm packages

Create package.json in the same directory:

json
{
  "type": "module",
  "dependencies": { "zod": "3.24.1" }
}
utf-8 · json · Lines: 4

Install the dependency:

Terminal
bash
elide install --ecosystems=npm

Plain elide install installs Maven dependencies and skips npm. If an import cannot find its package, check Module not found after elide install.

Save the greeting logic as greeting.ts:

ts
import { z } from "zod";

const User = z.object({ name: z.string() });

export function greeting(user: unknown): string {
  return `Hello, ${User.parse(user).name}!`;
}
utf-8 · ts · Lines: 7

Replace app.ts with:

ts
import { greeting } from "./greeting.ts";

console.log(greeting({ name: "Ada" }));
utf-8 · ts · Lines: 3
Terminal
bash
elide run app.ts
Hello, Ada!

This confirms the installed package imports and validates the input.

Installing npm dependencies and importing them from TypeScript
 ~/demo  elide install --ecosystems=npm
[479ms] ✓ NPM packages installed (477ms)
[481ms] ✓ Dependencies installed in 481ms
 ~/demo  elide run app.ts
Hello, Ada!
 









Packages go into node_modules. If the project also has Maven dependencies, use --ecosystems=maven,npm or --workspace. Lockfiles and options: NPM Installer.

Tests

Create greeting.test.ts beside the other files. elide test discovers *.test.ts files and runs node:test tests:

ts
import test from "node:test";
import assert from "node:assert";
import { greeting } from "./greeting.ts";

test("greets a named user", () => {
  assert.equal(greeting({ name: "Ada" }), "Hello, Ada!");
});

test("rejects a user without a name", () => {
  assert.throws(() => greeting({}));
});
utf-8 · ts · Lines: 11
Terminal
bash
elide test

Both tests should pass. If no tests are found, check the filename and run the command from hello-elide. More discovery rules and runner options: Testing.

Servers

Continue with Build an HTTP service for a complete server you can run and query. For an existing directory of web files:

Terminal
bash
elide serve --no-tui ./dist # static files on 127.0.0.1:8080
elide dev --no-tui ./src    # port 3000; pages reload on change

Given a script, serve and dev run it; a module that exports a fetch handler is served directly. See Development Server.

Executable scripts

On macOS and Linux, start a file with #!/usr/bin/env elide and mark it executable:

ts
#!/usr/bin/env elide
const name: string = process.argv[2] ?? "world";
console.log(`Hello, ${name}!`);
utf-8 · ts · Lines: 3

Save it as hello.ts, then run:

Terminal
bash
chmod +x hello.ts
./hello.ts Ada

The output is Hello, Ada!. The same first line works for .js, .mjs and .py files.

Samples

More

Extensions: .js, .mjs, .cjs, .jsx, .ts, .mts, .cts, .tsx. JSX and TSX are transformed; install the runtime they import, such as react/jsx-runtime. Elide provides no UI framework or DOM. See TypeScript and modules for module resolution and type checking.

Implemented Node and Web modules: API Overview. SQLite, PostgreSQL and MySQL drivers: Databases. Measured results: Compatibility Matrix. Traces, metrics, and logs through @opentelemetry/api, with no SDK: OpenTelemetry in JavaScript.

Was this page helpful?