For the complete documentation index, see llms.txt. This page is also available as Markdown.

Web Games (JS/TS) - Getting Started

Learn by doing and deploy your first Dedicated Server on Edgegap. By the end of this guide, you will have deployed a dedicated server with Edgegap at no cost.

This guide uses a minimal Node.js WebSocket server template, which works with any browser game client - Three.js, Babylon.js, PlayCanvas, Phaser, or your own engine. Servers built with frameworks like Colyseus, or running on Bun and Deno follow the same steps.

✔️ Preparation

Before you get started, make sure to create a free account with Edgegap (no credit card required). You can invite your team members afterwards, even if they don't have an Edgegap account yet.

Configure a few essentials on your development machine:

Install Node.js 22 or newer
Install Docker Desktop (or Docker CLI)

Confident in your server builds? Skip to Customize Image or Advanced Features for more.

⚙️ 1. Connect Account

JavaScript servers don't need an engine plugin. We'll use your command line and our Dashboard to build, upload, and deploy your server.

☑️ Sign in to our Dashboard and open Container Registry. Note your project name and registry credentials (username and token), you will need them in the next steps.

☑️ Sign in to Edgegap's Container Registry with Docker, using your registry project name, username and token:

☑️ Verify you see Login Succeeded in your command line.

✅ You may now proceed to the next step.

🔧 2. Build Game Server

Whether you’re using a Windows, Mac, or a Linux machine, your server will run on Linux runtime, as most cloud providers nowadays (including Edgegap) run on Linux. Good news - JavaScript is cross-platform, so there's nothing to cross-compile, and Docker will install your dependencies for Linux in the next step.

☑️ Create a new folder for your server with two files. This minimal template accepts WebSocket connections and relays every message to all connected players. Replace the relay with your game logic later on.

  1. Copy the server.js template in your project (unless you have one already):

  2. Copy the package.json in your project (or merge with existing).

☑️ Install dependencies and start your server locally:

☑️ Verify you see listening on 0.0.0.0:7777 and running locally in your console, then stop your server with Ctrl+C.

✅ You may now proceed to the next step.

🐋 3. Containerize Server

Working in a team of developers means sharing your code. When things go wrong, the last thing you want to hear is “it works on my machine”. Game servers have to run reliably on any machine, since a successful games’ servers will run on thousands of server machines across the world.

To help make your server reliable, we use Docker - virtualization software to ensuring that all of your server code dependencies down to the operating system level are going to be always exactly the same, no matter how or where the server is launched.

We recommend watching "Never install locally" (video). You DON'T need to use Dockerhub with Docker. Docker ≠ Dockerhub. Think of Docker as a programming engine and Dockerhub as it’s App Store.

☑️ Start by running docker version in your command line to ensure you’ve completed ✔️ Preparation.

Install Docker Desktop (or Docker CLI)

☑️ Add a Dockerfile and a .dockerignore file to your server folder, a recipe for your image:

Start your server with node, not npm start. Edgegap sends SIGTERM when your deployment stops, and only your container's main process receives it - handle it to implement graceful shutdown.

☑️ Build your image, choosing an image name and tag:

  • Image name is a unique identifier of your choice, labeling your server build before shipping.

    • Usually, this will include the name of your game - for example “my-game-server”.

    • Prefix it with registry.edgegap.com/<project>/ using your project name from step ⚙️ 1. Connect Account, so you can upload it later.

  • Image tag is an identifier pointing to a specific version of your image.

    • The term “build artifact” is sometimes used to refer to a specific version of your image.

    • Timestamps are a great default option for tagging, e.g. 2026.11.02-16.25.00-UTC .

  • Platform linux/amd64 ensures your image runs on Edgegap servers, even when building on a machine with ARM architecture (macOS M1, M2, M3, etc..).

☑️ Wait for the build to finish and verify there are no new errors in your command line. Completing this step will result in a new image appearing in your local machine. You can verify this either in Docker Desktop, in tab Images underneath Local (default), or in docker CLI by running docker images .

✅ You may now proceed to the next step.

🧪 4. Test Server Locally

Let’s try deploying locally (on your machine) and connecting a game client, to make sure the server image is functioning properly before we upload and deploy (which may take a bit of time).

☑️ Start a new container from your image:

  • -p {internal port}/{protocol} publishes and maps your server port 7777 to a random external port. WebSockets use the TCP protocol.

  • If you’re using a machine with ARM architecture (macOS M1, M2, M3, etc..) add parameter --platform=linux/amd64 .

☑️ Verify you see listening on 0.0.0.0:7777 in your command line. Completing this step will result in a new container being started on your development machine.

For more details see Docker Desktop / Containers, or Docker CLI command docker ps .

☑️ Now it’s time to connect a game client to your local docker container to verify your server image is functioning properly. Open two browser tabs, open developer tools console (F12) in each tab and connect to your container using:

  • localhost in place of server IP,

  • randomized external port value found in Docker Desktop / Containers.

☑️ Send a message from one tab with socket.send('hello') and verify that both tabs log received hello.

☑️ Once you’ve verified you’re able to connect to your local server container and play without issues, you may delete the container 🗑️ to free up resources on your machine for other programs.

✅ You may now proceed to the next step.

☁️ 5. Upload to Edgegap

It’s time to ship your server online! Now that your image can successfully host players, we can upload it to Edgegap and start running it anywhere in the world. In this guide, we’ll be using Edgegap’s Container Registry (storage for images).

☑️ Upload your image to Edgegap's Container Registry:

☑️ Wait for the upload to finish and verify there are no new errors in your command line. Completing this step will result in your build artifact being uploaded to Edgegap’s Container Registry.

☑️ Open our Dashboard and create a new Application. You may configure the following options (or keep defaults):

  • Application name on Edgegap can match your image name or be customized.

  • Application version on Edgegap can match your tag or be customized.

    • Timestamps are a great option for app version names, e.g. 2026.11.02-16.25.00-UTC .

    • Multiple application versions may point to the same image tag, such as v1.1.0 and dev .

    • Learn more about Apps and Versions later.

  • Image from step 🐋 3. Containerize Server, select your repository and tag.

  • Resources of 0.25 vCPU and 512 MB memory are plenty to get started with this template.

☑️ You will now be prompted to define a Port for your new Application version:

  • Port 7777 matching your server port from step 🔧 2. Build Game Server,

  • Protocol WS (WebSocket),

  • TLS Upgrade enabled,

  • Name gameport.

TLS Upgrade lets browsers connect with secure WebSockets (wss://). Pages served over https:// can't open unsecured ws:// connections, so keep TLS Upgrade enabled for browser games.

Free Tier is limited to 2 Applications, 2 versions, and 10 GB of Container Registry storage.

✅ You may now proceed to the next step.

🚀 6. Deploy to Cloud

This is the final step in this guide, after which you will have a server deployed on Edgegap cloud, to which players from anywhere in the world can connect.

☑️ Choose an application and version from previous step to deploy.

☑️ Once you’re ready, hit Deploy to Cloud, wait to reach 3. Deployment Ready. Completing this step will result in a new Deployment being started on your Edgegap account.

☑️ Verify there are no new errors in your console output. Ensure also that your Container Logs don’t show any errors and your Container Metrics don’t indicate 100% resource utilization (vCPU or memory), otherwise new player connections may be rejected, or your server stuck in a restart loop. See troubleshooting steps below to address any issues.

☑️ Now we’ll perform the final test and connect your game client to your cloud deployment. Grab your Deployment’s Host in place of server IP and the External Port of gameport, and connect with secure WebSockets from your browser console:

The external port of your Deployment on Edgegap cloud will be chosen at random, so that a potential attacker (hacker) is slowed down and detected before they can cause damage.

☑️ Once you verify you’re able to connect to your Deployment without issues and are done testing, Stop your Deployment to free up capacity in your account for the next build.

🙌 Congratulations on your first Deployment on Edgegap! If you’d like to learn more, keep reading.

👉 Next Steps

Once you have a working client/server setup, make sure to save a copy of your project (using version control software like git) so you can always trace back your steps in case you run into issues.

Continue reading to learn more about topics related to server lifecycle and discoverability.

If you need help, please reach out to us over Discord. For live games support see our ticketing system.

Stop Deployments

Once the match ends (or players leave), your deployment can be stopped to save cost. Running empty or only partially filled deployments can increase your cost unnecessarily!

Stop your deployment from your server code, Edgegap will then send SIGTERM to your server:

Injected Variables

Read useful information like deployment ID, server IP address, server location, and more; by accessing injected environment variables. Each deployment automatically includes:

Read any variable with process.env, or parse them into typed objects with our optional SDK:

Parsing never throws, so the same server runs locally. Missing variables are listed in a single warning.

Session Automation

When testing new builds with developers or QA teams, the session step is often skipped and players connect directly to deployments while hard-coding or disabling session related features. This enables faster development iteration and isolates session side effects from server features.

Automate popular game flows for Player Sessions and server scaling with either:

Matchmaking:

  • Competitive Games

  • On-Demand Matches

  • Skill Rating and/or Custom Rules

Server Browser:

  • Persistent or Social

  • Long Sessions

  • Auto-Assign and/or Custom Search

Custom Backend:

Samples

Get inspired by five browser multiplayer minigames built with Three.js and authoritative Node.js servers. Includes matchmaking from the browser, one image for multiple games, team assignment, and deployments that stop themselves when the match ends.

Optimize Usage

A few tips to get started with optimizing your server usage:

Higher tick rate means more updates, requiring more CPU usage and data egress.

  • Browser games often simulate at 30-60 ticks per second and send state to players at 10-20 Hz, with clients interpolating between updates. Our Three.js sample sends 20 updates per second.

  • Node.js runs your game loop on a single thread, so a slow tick delays messages for every player. Tread carefully if your game has many players per match (10+), complex physical simulations, or many bot opponents/teammates. Profile your server with node --cpu-prof to find hot spots.

  • JSON messages are easy to debug, binary messages (ArrayBuffer) reduce data egress for frequent state updates.

How to choose the right networking protocol? Make it work first, then make it better.

  • Browsers can't open raw UDP or TCP connections, only WebSocket, WebRTC, and WebTransport. WebSockets are a great default choice providing compatibility across the biggest range of devices and networks.

  • Some fast-paced games may want to experiment with WebRTC data channels or WebTransport for unreliable delivery, but it will certainly require extra development efforts. Ask yourself if this is critical for your target audience.

  • Pick your battles carefully, game development has no shortage of challenges.

Customize Image

Your Dockerfile from step 🐋 3. Containerize Server can be customized for build size optimization, extraneous dependencies, or requiring more complex startup process. We’ll now share a few “do it yourself” tips and best practices.

Bundle your server into a single file with a multi-stage build.

  • Bundlers like esbuild compile TypeScript and combine your code and dependencies into one file, so your final image doesn't need node_modules or source files. Savings grow with the size of your dependency tree.

  • Install esbuild with npm install --save-dev esbuild and replace your Dockerfile with:

Always make sure you are working with a functioning server build.

  • Before assuming an issue is related to the custom Dockerfile, ensure your server build can be started, and that the build process in your game engine didn’t throw any exceptions or errors.

Always test locally before uploading.

  • Testing your image locally will save you lots of time while waiting for the upload to finish. It’s also entirely free ✨ as it doesn’t require any Edgegap resources.

  • When testing locally, make sure to set your internal port correctly:

Make sure you’ve got the basics down. Every Dockerfile needs a few essential commands:

  • FROM {image} is your base image, we usually use a long-term supported Linux, but any Linux-based base image will do. These are usually public images stored on dockerhub. Dockerfile reference here. Dockerfile reference here.

  • COPY {source} {destination} to copy your linux server build from your host machine inside the image, so you can start it later on. Dockerfile reference here.

  • USER {user} should follow after a useradd (ubuntu) command or equivalent, it’s best not to run everything as root to be on the safer side. Dockerfile reference here.

  • CMD {command} will be the last line, most likely calling a StartServer.sh or some kind of startup script to make sure your server initializes correctly once everything is set up. Dockerfile reference here.

  • do NOT use VOLUME - you will not be able to mount any local storage this way on Edgegap, consider our Endpoint Storage feature instead and use an S3 bucket, see Endpoint Storage,

  • EXPOSE 7777/UDP is not required! This will not actually make the internal server port available from outside the container, it's only a hint for the developer and the port needs to be

    • published when testing locally with docker run <image> -p 7777/udp ,

    • or mapped in Edgegap Port Mapping.

Delay declaration of parameters until latest possible moment. Configurability > composability due to long server build times. Apply this approach to Dockerfile commands to build and upload faster.

  • Scenario: you need to define parameters like deployment stage, version, game mode, map, player count per server, backup frequency, or similar.

  • Bad solution: creating a separate image for every combination of your parameters. You will spend all of your time rebuilding the images with very little benefits from this approach.

  • Better solution - substitute configuration parameters just in time:

    1. deployment parameters - supplied just before the deployment is made - matchmaking selectors passed as environment variables, or your custom session management system passing environment variables at deployment time,

    2. version parameters - shared for all deployments on an app version - deployment stage, artifact tag, third party secrets and endpoints, and similar; then

    3. one single image - contains and loads all configuration options when launched.

Do NOT run databases on Edgegap deployments.

  • Edgegap deployments are not intended for long-running processes and may be terminated after a long period of runtime without prior notice. A database (even if distributed) running in this manner may be terminated and result in an irreversible loss of data. If you need a database, please consider a third party DBaaS.

  • Consider using our Managed Clusters for hosting databases and long running services.

Last updated

Was this helpful?