Comprehensive technical documentation for the node-cs2 library.
- Architecture
- API Reference
- Event Reference
- Protobuf Messages
- Field Reference
- Error Handling
- Performance Considerations
- Troubleshooting
node-cs2 is built on top of steam-user and communicates with the CS2/CS:GO Game Coordinator (GC) using protobuf messages. The library provides a high-level API that abstracts away the complexity of protobuf encoding/decoding and message routing.
-
NodeCS2 Class (
index.js)- Main entry point
- Manages GC connection
- Provides public API methods
- Handles message sending
-
Message Handlers (
handlers.js)- Processes incoming GC messages
- Decodes protobuf data
- Emits events for application use
-
Message IDs (
language.js)- Maps message names to numeric IDs
- Used for routing messages
-
Enums (
enums.js)- Defines constants (GCConnectionStatus, ItemCustomizationNotification)
- Used throughout the library
-
Constants (
constants.js)- Named constants replacing magic numbers (timeouts, attribute indices, app IDs, etc.)
- Improves readability and maintainability
-
Protobuf Definitions (
protobufs/generated/)- Auto-generated from
.protofiles - Provides message encoding/decoding
- Auto-generated from
-
TypeScript Definitions (
types/index.d.ts)- Full type definitions for all public APIs, events, and data structures
- Enables IntelliSense and compile-time checking in TypeScript projects
Application → NodeCS2 → steam-user → Game Coordinator
↓
EventEmitter
↓
Application Handlers
new NodeCS2(steamUser);Parameters:
steamUser(SteamUser) - An instance ofsteam-userv4.2.0+
Throws:
Errorifsteam-userversion is incompatible
Sends a hello message to the Game Coordinator to establish connection.
cs2.helloGC();Returns: undefined
Inspects an item from another player's inventory.
Parameters:
owner(string|number) - SteamID64 of the item ownerassetid(string|number) - Asset ID of the itemd(string|number) - D parameter (usually class ID)callback(function, optional) - Callback function(item) => {}
Returns:
- If callback provided:
undefined - If no callback:
Promise<Object>- Resolves with item data
Item Object Structure:
{
itemid: number,
defindex: number,
paintindex: number,
paintseed: number,
paintwear: number,
rarity: number,
quality: number,
musicindex: number,
entindex: number,
petindex: number,
style: number,
upgrade_level: number,
stickers: Array<StickerObject>,
keychains: Array<KeychainObject>,
variations: Array<VariationObject>
}Events Emitted:
inspectItemInfo- When item data is receivedinspectItemInfo#<assetid>- Specific item eventinspectItemTimedOut- When inspection times outinspectItemTimedOut#<assetid>- Specific timeout event
Gets the contents of a casket (container item).
Parameters:
casketId(number) - ID of the casket itemcallback(function, optional) - Callback function(err, items) => {}
Returns:
- If callback provided:
undefined - If no callback:
Promise<Array>- Resolves with array of items
Events Emitted:
itemCustomizationNotification- When casket contents are loaded
Loads the contents of a volatile item (rental/temporary item).
Parameters:
volatileItemId(number) - ID of the volatile itemcallback(function, optional) - Callback function(err, items) => {}
Returns:
- If callback provided:
undefined - If no callback:
Promise<Array>- Resolves with array of items
Timeout: Configurable via _volatileItemTimeout (default: 30000ms)
Claims a reward from a volatile item.
Parameters:
defindex(number) - Definition index of the volatile itemcallback(function, optional) - Callback function(err, itemIds) => {}
Returns:
- If callback provided:
undefined - If no callback:
Promise<Array>- Resolves with array of item IDs
Timeout: Configurable via _volatileItemTimeout (default: 30000ms)
Acknowledges rental expiration for a crate/item.
Parameters:
crateItemId(number) - ID of the crate/item
Returns: undefined
Requests the recurring mission schedule.
Parameters:
callback(function, optional) - Callback function(err, schema) => {}
Returns:
- If callback provided:
undefined - If no callback:
Promise<Object>- Resolves with mission schema
Schema Structure:
{
missions: [
{
period: number,
mission_templates: Array<Buffer>
}
]
}Events Emitted:
recurringMissionSchema- When schema is received
Timeout: Configurable via _missionTimeout (default: 10000ms)
Acknowledges XP shop tracks.
Parameters: None
Returns: undefined
Redeems a free reward.
Parameters:
generationTime(number) - Generation time of the rewardredeemableBalance(number) - Redeemable balanceitems(Array) - Array of item IDscallback(function, optional) - Callback function(err, itemIds) => {}
Returns:
- If callback provided:
undefined - If no callback:
Promise<Array>- Resolves with array of item IDs
Timeout: Configurable via _rewardTimeout (default: 10000ms)
Redeems a mission reward.
Parameters:
campaignId(number) - Campaign IDredeemId(number) - Redeem IDredeemableBalance(number) - Redeemable balanceexpectedCost(number) - Expected costbidControl(number, optional) - Bid control valuecallback(function, optional) - Callback function(err, itemIds) => {}
Returns:
- If callback provided:
undefined - If no callback:
Promise<Array>- Resolves with array of item IDs
Timeout: Configurable via _rewardTimeout (default: 10000ms)
Sets the player's leaderboard safe name.
Parameters:
leaderboardSafeName(string) - The safe name for leaderboards
Returns: undefined
Throws:
ErrorifleaderboardSafeNameis not a non-empty string
Opens a crate using a key.
Parameters:
toolItemId(number) - The ID of the tool (key) itemsubjectItemId(number) - The ID of the crate itemforRental(boolean, optional) - Whether this is for a rentalpointsRemaining(number, optional) - Points remainingcallback(function, optional) - Callback function(err, itemIds) => {}
Returns:
- If callback provided:
undefined - If no callback:
Promise<Array>- Resolves with array of item IDs
Timeout: Configurable via _crateTimeout (default: 30000ms)
Extracts a sticker from an item.
Parameters:
itemId(number) - The ID of the item with the stickerstickerSlot(number) - The slot number of the sticker to extractcallback(function, optional) - Callback function(err, itemIds) => {}
Returns:
- If callback provided:
undefined - If no callback:
Promise<Array>- Resolves with array of item IDs
Timeout: Configurable via _stickerTimeout (default: 10000ms)
Encapsulates a sticker.
Parameters:
stickerId(number) - The ID of the sticker to encapsulatecallback(function, optional) - Callback function(err, itemIds) => {}
Returns:
- If callback provided:
undefined - If no callback:
Promise<Array>- Resolves with array of item IDs
Timeout: Configurable via _stickerTimeout (default: 10000ms)
Applies a patch to an item.
Parameters:
itemId(number) - The ID of the item to apply patch topatchId(number) - The ID of the patch itempatchSlot(number, optional) - The slot number for the patchcallback(function, optional) - Callback function(err, itemIds) => {}
Returns:
- If callback provided:
undefined - If no callback:
Promise<Array>- Resolves with array of item IDs
Timeout: Configurable via _stickerTimeout (default: 10000ms)
Removes a patch from an item.
Parameters:
itemId(number) - The ID of the item with the patchpatchSlot(number) - The slot number of the patch to removecallback(function, optional) - Callback function(err, itemIds) => {}
Returns:
- If callback provided:
undefined - If no callback:
Promise<Array>- Resolves with array of item IDs
Timeout: Configurable via _stickerTimeout (default: 10000ms)
Applies a keychain to an item.
Parameters:
itemId(number) - The ID of the item to apply keychain tokeychainId(number) - The ID of the keychain itemkeychainSlot(number, optional) - The slot number for the keychaincallback(function, optional) - Callback function(err, itemIds) => {}
Returns:
- If callback provided:
undefined - If no callback:
Promise<Array>- Resolves with array of item IDs
Timeout: Configurable via _stickerTimeout (default: 10000ms)
Removes a keychain from an item. This is a fire-and-forget operation — it sends the removal request to the Game Coordinator without waiting for a response.
Parameters:
itemId(string) - The ID of the item with the keychain
Returns: undefined
Requests a player's profile data.
Parameters:
steamid(string|SteamID) - SteamID of the playercallback(function, optional) - Callback function(err, profile) => {}
Returns:
- If callback provided:
undefined - If no callback:
Promise<Object>- Resolves with profile data
Timeout: Configurable via _profileTimeout (default: 10000ms)
Events Emitted:
playersProfile- When profile is receivedplayersProfile#<steamid64>- Specific profile event
haveGCSession(boolean) - Whether GC session is active_isInCSGO(boolean) - Whether CS2/CS:GO is launched
_inspectTimeout(number) - Inspection timeout in ms (default: 10000)_casketTimeout(number) - Casket loading timeout in ms (default: 30000)_profileTimeout(number) - Profile request timeout in ms (default: 10000)_volatileItemTimeout(number) - Volatile item timeout in ms (default: 30000)_missionTimeout(number) - Mission request timeout in ms (default: 10000)_rewardTimeout(number) - Reward redemption timeout in ms (default: 10000)_crateTimeout(number) - Crate opening timeout in ms (default: 30000)_stickerTimeout(number) - Sticker/patch/keychain operations timeout in ms (default: 10000)
Emitted when connected to the Game Coordinator.
No parameters
Emitted when disconnected from the Game Coordinator.
No parameters
Emitted when GC connection status changes.
Parameters:
status(number) - Connection status code0= HAVE_SESSION1= GC_GOING_DOWN2= NO_SESSION3= NO_SESSION_IN_LOGON_QUEUE4= NO_STEAM
Emitted when item inspection data is received.
Parameters:
item(Object) - Item data object
Emitted for a specific item inspection.
Parameters:
item(Object) - Item data object
Emitted when an item inspection times out.
Parameters:
assetid(number) - Asset ID that timed out
Emitted when an item customization notification is received.
Parameters:
itemIds(Array) - Array of affected item IDsnotificationType(number) - Notification type (see ItemCustomizationNotification enum)
Emitted when player profile data is received.
Parameters:
profile(Object) - Profile data object
Emitted for a specific player profile.
Parameters:
profile(Object) - Profile data object
Emitted when XP shop notification is received.
Parameters:
data(Object) - XP shop dataprematch(Object) - Prematch XP shop datapostmatch(Object) - Postmatch XP shop datacurrent_xp(number) - Current XPcurrent_level(number) - Current level
Emitted when recurring mission schema is received.
Parameters:
schema(Object) - Mission schema object
Emitted when premier season summary is received.
Parameters:
summary(Object) - Premier season summary data
Emitted when matchmaking search statistics are received.
Parameters:
stats(Object) - Search statistics object
Emitted when an error occurs.
Parameters:
error(Error) - Error object
Emitted for debug messages.
Parameters:
message(string) - Debug message
All message IDs are defined in language.js. Common message IDs:
ClientHello: 4006Client2GCEconPreviewDataBlockRequest: 2001Client2GCEconPreviewDataBlockResponse: 2002CasketItemLoadContents: 2003VolatileItemLoadContents: 2536GC2ClientNotifyXPShop: 9221RequestRecurringMissionSchedule: 9225RecurringMissionSchema: 9226PremierSeasonSummary: 9224
See language.js for complete list.
itemid(number) - Item IDdefindex(number) - Definition indexpaintindex(number) - Paint/skin indexpaintseed(number) - Paint seedpaintwear(number) - Wear value (0-1)rarity(number) - Rarity levelquality(number) - Quality level
musicindex(number) - Music kit indexentindex(number) - Entity indexpetindex(number) - Pet/companion indexstyle(number) - Style variation indexupgrade_level(number) - Item upgrade level
All sticker-like items (stickers, keychains, variations) share the same structure:
{
slot: number, // Slot number
sticker_id: number, // Sticker/item ID
wear: number, // Wear value (0-1)
scale: number, // Scale factor
rotation: number, // Rotation angle
tint_id: number, // Tint color ID
offset_x: number, // X offset
offset_y: number, // Y offset
offset_z: number, // Z offset
pattern: number, // Pattern index
highlight_reel: number, // Highlight reel ID
wrapped_sticker: number // Wrapped sticker ID
}-
Timeout Errors
- Occur when operations exceed timeout duration
- Message:
"<operation> timed out" - Solution: Increase timeout or retry
-
Protobuf Decoding Errors
- Occur when received data is malformed
- Emitted via
errorevent - Solution: Check network connection, retry
-
Validation Errors
- Occur when invalid parameters are provided
- Thrown immediately
- Solution: Validate input before calling
-
Connection Errors
- Occur when GC connection is lost
- Emitted via
errorevent - Solution: Reconnect to GC
- Always handle errors in Promise chains
- Listen for
errorevents - Validate input before calling methods
- Use appropriate timeouts for operations
- Implement retry logic for transient failures
Default timeouts are conservative. Adjust based on your use case:
- Inspection: 10s (usually fast)
- Casket Loading: 30s (can be slow)
- Profile Requests: 10s (usually fast)
- Volatile Items: 30s (can be slow)
- Missions: 10s (usually fast)
- Rewards: 10s (usually fast)
When inspecting multiple items, add delays between requests:
for (const item of items) {
await cs2.inspectItem(item.owner, item.assetid, item.classid);
await new Promise((resolve) => setTimeout(resolve, 1000)); // 1s delay
}The library maintains minimal state. Inventory data is managed by steam-user.
- Cause: Item doesn't exist, owner is offline, or GC is slow
- Solution: Verify item exists, check owner status, increase timeout
- Cause: Malformed data received from GC
- Solution: Retry operation, check network connection
- Cause: Invalid SteamID format provided
- Solution: Use valid SteamID64 or SteamID object
- Cause: Network issues or GC restart
- Solution: Reconnect to GC, check network
Enable debug logging:
cs2.on('debug', (message) => {
console.log('[CS2]', message);
});This will log all GC messages and connection status changes.
For usage examples, see EXAMPLES.md.