Quick Start
Deploy your first game server in 5 minutes
Quick Start Guide
Get your first CS2 game server running in just a few minutes.
Prerequisites
- Node.js 18+ installed
- A SweatHost account (sign up here)
- An API key from your dashboard
Step 1: Install the SDK
Install the SweatHost SDK using your preferred package manager:
npm install @sweathost/sdkpnpm add @sweathost/sdkyarn add @sweathost/sdkStep 2: Get Your API Key
- Log in to your SweatHost Dashboard
- Navigate to API Keys in the sidebar
- Click Create API Key
- Name your key (e.g., "Development")
- Select scopes:
servers:read,servers:write,servers:control - Copy the API key (save it securely!)
Important: Your API key will only be shown once. Store it securely!
Step 3: Initialize the SDK
Create a new file server.ts and initialize the SDK:
import { SweatHostClient } from '@sweathost/sdk';
const client = new SweatHostClient({
apiKey: process.env.SWEATHOST_API_KEY!,
});
console.log('✓ SDK initialized');Step 4: Create Your First Server
Add this code to create a CS2 server:
async function createServer() {
try {
// Create a new CS2 server
const server = await client.gameServers.create({
name: 'My First CS2 Server',
region: 'us-west-1',
game: 'cs2',
maxPlayers: 10,
config: {
gameMode: 'competitive',
tickrate: 128,
map: 'de_dust2',
},
});
console.log('✓ Server created!');
console.log(` ID: ${server.id}`);
console.log(` Name: ${server.name}`);
console.log(` Status: ${server.status}`);
console.log(` IP: ${server.ipAddress}:${server.port}`);
return server;
} catch (error) {
console.error('✗ Failed to create server:', error.message);
throw error;
}
}
createServer();Step 5: Start the Server
Once created, start your server:
async function startServer(serverId: string) {
try {
await client.gameServers.start(serverId);
console.log('✓ Server starting...');
// Wait for server to be ready
let server;
do {
await new Promise(resolve => setTimeout(resolve, 2000));
server = await client.gameServers.get(serverId);
console.log(` Status: ${server.status}`);
} while (server.status !== 'running');
console.log('✓ Server is ready!');
console.log(` Connect: connect ${server.ipAddress}:${server.port}`);
} catch (error) {
console.error('✗ Failed to start server:', error.message);
}
}Complete Example
Here's the complete code to create and start a server:
import { SweatHostClient } from '@sweathost/sdk';
const client = new SweatHostClient({
apiKey: process.env.SWEATHOST_API_KEY!,
});
async function main() {
console.log('🎮 SweatHost Quick Start\n');
// Step 1: Create server
console.log('Creating server...');
const server = await client.gameServers.create({
name: 'My First CS2 Server',
region: 'us-west-1',
game: 'cs2',
maxPlayers: 10,
config: {
gameMode: 'competitive',
tickrate: 128,
map: 'de_dust2',
},
});
console.log(`✓ Server created: ${server.id}\n`);
// Step 2: Start server
console.log('Starting server...');
await client.gameServers.start(server.id);
// Step 3: Wait for ready
let status = 'starting';
while (status !== 'running') {
await new Promise(resolve => setTimeout(resolve, 2000));
const updated = await client.gameServers.get(server.id);
status = updated.status;
console.log(` Status: ${status}`);
}
console.log('\n✓ Server is ready!');
console.log(`\n📍 Connection Info:`);
console.log(` IP: ${server.ipAddress}`);
console.log(` Port: ${server.port}`);
console.log(` Connect: connect ${server.ipAddress}:${server.port}`);
console.log(`\n🎮 Your server is now live!`);
}
main().catch(console.error);Run Your Code
# Set your API key
export SWEATHOST_API_KEY="your-api-key-here"
# Run the script
npx tsx server.tsExpected output:
🎮 SweatHost Quick Start
Creating server...
✓ Server created: srv_abc123
Starting server...
Status: starting
Status: provisioning
Status: running
✓ Server is ready!
📍 Connection Info:
IP: 192.168.1.100
Port: 27015
Connect: connect 192.168.1.100:27015
🎮 Your server is now live!Managing Your Server
Get Server Status
const server = await client.gameServers.get('server-id');
console.log(`Status: ${server.status}`);
console.log(`Players: ${server.currentPlayers}/${server.maxPlayers}`);Execute RCON Commands
const result = await client.gameServers.rcon('server-id', 'status');
console.log(result.output);Stop the Server
await client.gameServers.stop('server-id');
console.log('Server stopped');Delete the Server
await client.gameServers.delete('server-id');
console.log('Server deleted');Next Steps
Now that you have a server running, explore more features:
Game Servers API
Learn all server management features
Match Analytics
Access match data and statistics
Regions
Choose optimal server locations
Error Handling
Handle errors gracefully
Common Issues
"Invalid API key"
Make sure you're using the correct API key and it has the required scopes (servers:read, servers:write, servers:control).
"Region not available"
Check available regions with:
const regions = await client.regions.list();
console.log(regions.map(r => r.code));"Insufficient quota"
You may have reached your server limit. Check your plan in the dashboard or delete unused servers.
Get Help
Need assistance?