> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gcore.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Set up JavaScript for FastEdge

The FastEdge JavaScript SDK (`@gcoredev/fastedge-sdk-js`) compiles JavaScript applications to WebAssembly so they can run on Gcore's edge network. It is the recommended way to build FastEdge applications in JavaScript.

[Node.js](https://nodejs.org) v22 or higher is required.

## Install the SDK

The steps below set up a minimal project manually. To scaffold a project from a template instead, run `npm create fastedge-app` — it handles folder creation, dependency installation, and project structure interactively.

```sh theme={null}
mkdir my-app
cd my-app
npm init -y
npm install --save-dev @gcoredev/fastedge-sdk-js
```

`npm init -y` creates `package.json` with `"type": "commonjs"` by default. The SDK bundler requires ESM — change it before building:

```sh theme={null}
npm pkg set type=module
```

After installation, three CLI tools are available via `npx`:

| Tool              | Purpose                                     |
| ----------------- | ------------------------------------------- |
| `fastedge-build`  | Compiles JavaScript to a WebAssembly binary |
| `fastedge-init`   | Creates build config for repeatable builds  |
| `fastedge-assets` | Packages static files for edge serving      |

## Write a handler

FastEdge applications register a `fetch` event listener that receives an HTTP request and returns a response. Create `src/index.js`:

```js theme={null}
addEventListener('fetch', (event) => {
  event.respondWith(new Response('Hello from FastEdge'));
});
```

The `fetch` event model follows the [Service Worker API](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API) convention. `event.respondWith()` accepts a `Response` object or a `Promise<Response>`. Under the hood, the SDK compiles to the [WASI P2](https://wasi.dev/releases/wasi-p2) `wasi:http/proxy` world — the same standard used by the Modern Rust SDK.

## Verify the toolchain

Compile the handler to a WebAssembly binary:

```sh theme={null}
npx fastedge-build --input src/index.js --output wasm/app.wasm
```

A successful build prints:

```
Build success!!
"src/index.js" -> "wasm/app.wasm"
```

The compiled binary is at `./wasm/app.wasm`. That file can be uploaded to FastEdge directly or used as the starting point for the next tutorial.
