ODIN Fleet Node.js SDK
This is the Node.js SDK designed to interact with the Fleet REST API, enabling developers to manage game servers efficiently. This SDK leverages the robust and scalable solutions offered by ODIN Fleet, making it easier to deploy and manage game servers across a global network.
Features
- Server Management: Create, configure, deploy, and autoscale game servers.
- CI/CD Integration: Seamlessly integrate into CI/CD pipelines for automated server management.
- Cross-Platform Support: Compatible with various game engines and platforms.
- Real-Time Scaling: Dynamically adjust the number of servers based on demand.
- User-Friendly Interface: Simple API, dashboard, and CLI for easy server management.
- Security: Built-in DDoS protection and GDPR/DSGVO compliance.
Installation
Install the SDK using npm:
Usage
Initialization
First, import and initialize the FleetApiClient
with your API key:
In TypeScript, you can import the SDK as follows:
Dashboard
Using our dashboard is an easy way of managing your game servers and applications. It's also a good way to see which items are created by the examples and how they are structured.
You'll find the dashboard at https://console.4players.io. All you need is a 4Players account which you can also create on the dashboard.
Next Steps
The following examples demonstrate how to use the FleetApiClient SDK to manage game servers using the Fleet API.
Example: Deploying a Minecraft Server
Depending on your business model you typically have your own docker image or have server binaries in Steam, but in this case we'll use an existing Minecraft Docker image to deploy a Minecraft server.
Although you can create an App via Script, it's easier to understand and to follow if we create the app in the dashboard as we need an API key for the script to work, so let's create an app in the dashboard.
Navigate to the dashboard and create a new app. You can name it whatever you want, but for this example we'll name it
Minecraft
.
Once you have created the App, you'll be routed to the apps dashboard where the App-ID is displayed. You'll need this ID
for the script.
Click on the Copy button to copy the App-ID to your clipboard.
Let's start with the initial part of the script:
Next, click on "Settings" on the left sidebar and choose "API-Keys" from the list. You'll see your personal Access Token. Click the copy icon again and paste it into the script.
Now we need to create an image. We'll use the Minecraft image from the Docker Hub. You can find the image here.
Next, we'll need to create a server config. A server config is a blueprint for a server. It defines the image, required resources, persistence, and other settings. This is a bit more complex and it might be helpful to play around with the dashboard to understand the structure of the server config.
As with most docker images, they are configured via environment variables. Which environment variables are available is defined in the Dockerfile. In this case, we'll set the EULA to true, the server name to "ODIN Fleet", the MOTD to " Welcome to our ODIN Fleet Minecraft Server", the max players to 10, and disable the snooper.
You'll find more info in these variables here.
Now we can deploy the server. We'll deploy 1 server in this example. We'll use the german region to deploy it.
That's it. You should now have a Minecraft server running in the german region. You can now connect to it using the IP address of the server.
Make sure to delete the deployment and the server config if you don't need them anymore. You can also delete the binary if you don't need it anymore.
You'll find a list of deployed servers in the dashboard under "Servers".
Getting a servers IP and Port
When you create a server config you define which ports need to be routed to the internet. In the above server config we created a port definition named "Game Port" and defining a TCP port at 25565. Our system will find a free port on the maschine and will route that port to the internal port where the gameserver is listening. To find out which port is used you can get the server details:
Development
We are using OpenAPI to document our APIs and use generators to automatically build client code. However, as these
generators have their weaknesses, we create a custom wrapper around the generated code to make it more user-friendly. In
this case it's the FleetApiClient
. You can update the internal code by running the following command:
This will download the current API specs from the backend and generate the client code. Typically some minor changes or
additions are then required to FleetApiClient
.
Open-Source
This SDK is open-source and available on GitHub.
API Documentation
The full API documentation is available in the OpenAPI specs: Fleet API Documentation.
Support
For additional support, get in touch on our Discord server.
Book a meeting or join a live presentation to learn more about ODIN Fleet and how it can help manage your game servers efficiently.
License
The NodeJS SDK is MIT License.