# Host a room

> Create a room in the Creator Portal and launch it from Node with @disko-game/room.

A room is a program you run, on your computer or a server. Players' browsers
connect straight to it, and it runs the game for everyone in it. disko's own
services only help players find your room and check who they are.

```mermaid alt="Your room program uses its room id and token to register with disko and appear in the directory. It loads a game release from the registry. Players find the room in the directory and then connect directly to your room."
flowchart TB
  portal["Creator Portal"] -- "room id + token" --> room["Your room<br/>(Node)"]
  room -- "register with id + token" --> directory["disko directory"]
  registry[("Registry")] -- "game release" --> room
  players["Players"] -- "find the room" --> directory
  players <-- "play" --> room
```

## 1. Create a room identity

In the Creator Portal, open **Rooms** and create a room. You get a **room id** and
a **hosting token**, shown only once.

The token is the room's password: anyone who has it can run a room under your
name. Keep it out of your code and your repository.

## 2. Create a room project

```sh
npm create @disko-game -- room my-room --js
cd my-room
npm install
```

The project has two files:

- **`room.js`** holds the **host function**, which starts the room and decides
  how it behaves, for example what happens to chat. This is where your own
  code goes.
- **`main.js`** reads the settings from environment variables and calls the
  host function. It's what you run.

```js title="room.js"
import { Room } from "@disko-game/room";

// The host function. `main.js` calls it in production and `disko dev` calls
// it with a test room: pass `options` through to `Room.launch` and return
// the room.
/** @param {import("@disko-game/room").HostOptions} options */
export default async function host(options) {
  const room = await Room.launch({ ...options, name: "My disko room" });

  // Nothing appears in chat unless the room sends it.
  room.on("chat-request", ({ player, text }) => {
    void room.send({ author: player, content: text });
  });

  room.on("player-join", ({ player }) => {
    void room.send(`${player.name} joined`);
  });

  return room;
}
```

## 3. Run it

Pass the room id, the token and the release to load:

```sh
ROOM_ID=… ROOM_TOKEN=… GAME=gabriel/arena@1.4.2 npm start
```

To find a game, browse the [Registry](https://registry.disko.ooo). Each game's
page has its description, its versions and the release to copy.

When the room is ready, share `room.link` (`https://play.disko.ooo/?room=<id>`)
with players. To host on a server, open UDP ports 4433–4532 in its firewall;
see [Running on a server](/rooms/running-on-a-server).

## Next

- [`Room.launch` & options](/rooms/launch)
- [Events, chat & lifecycle](/rooms/events-chat-lifecycle)
