# JavaScript and TypeScript with Elide

> Run JavaScript and TypeScript, install npm packages, test, and serve with Elide

Elide runs JavaScript and TypeScript directly, with CommonJS, ES modules, and a subset of the Node and Web APIs.
TypeScript needs no compile step and no `tsconfig.json`.

```bash
elide run app.js
elide run app.ts
elide app.ts
elide run -s 'console.log(1 + 1)'
```

Extensions: `.js`, `.mjs`, `.cjs`, `.jsx`, `.ts`, `.mts`, `.cts`, `.tsx`. JSX and TSX are transformed, but Elide
provides no UI framework or DOM; install what your code imports, such as React's `react/jsx-runtime`.

## npm packages

Declare dependencies in `package.json`. Plain `elide install` skips npm, so pass `--ecosystems=npm`:

```json
{
  "type": "module",
  "dependencies": { "zod": "3.24.1" }
}
```

```ts
// app.ts
import { z } from "zod";

const User = z.object({ name: z.string() });
console.log(`Hello, ${User.parse({ name: "Ada" }).name}!`);
```

```bash
elide install --ecosystems=npm
elide run app.ts
```

<img src="https://elide.help/assets/demos/npm-install.gif" alt="elide install — package.json dependencies used from TypeScript" width="1591" height="764" loading="lazy" decoding="async" class="rounded-lg border border-border my-6 w-full" />

Packages are installed into `node_modules`. Use `--ecosystems=maven,npm` or `--workspace` when the project also has
Maven dependencies. See [NPM Installer](https://elide.help/docs/toolchain/web/npm) for lockfiles and options.

## Tests

`elide test` finds `*.test.ts`, `*.spec.js`, files under `test/`, and similar. Write them with `node:test`:

```ts
// math.test.ts
import test from "node:test";
import assert from "node:assert";

test("adds", () => {
  assert.equal(1 + 1, 2);
});
```

```bash
elide test
```

## Servers

```bash
elide serve --no-tui ./dist # static files on 127.0.0.1:8080
elide dev --no-tui ./src    # live reload on port 3000
```

Given a script, `serve` and `dev` run it; a module that exports a `fetch` handler is served directly. See
[Development Server](https://elide.help/docs/dev-server).

## More

Implemented Node and Web modules are listed in the [API Overview](https://elide.help/docs/api-overview); measured results are in the
[Compatibility Matrix](https://elide.help/docs/compatibility).
