TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published


GameGuard is a NodeJS game server that can be used to manage the players connecting to your game, manage rooms and the players in them, and more.

NPM version Known Vulnerabilities npm NPM downloads issues license Gitter

Note: This is the post 1.0.0 version of GameGuard that has lots of breaking changes from the last version due to major simplification. All of the previous features still exist but the API has changed to be more simple and streamlined. GameGuard can now be used on it's own but it has been simplified in order to be able to be extended further to suit your needs.

Note About Logging: For now, GameGuard has no logging capability. I've gone back and forth about implementing logging but I've found it to be so customizable it would be much easier for the end user to implement using signals but if there's enough requests then logging can be implemented to be a core part of GameGuard.

Table of Contents


To install GameGuard you need the server side package (this one) and then a client-side package. Currently only gameguard-client is supported but in the future there will be guides on creating your own client side solution to communicate with the GameGuard server.

To install GameGuard you can use:

$ npm install gameguard

and if you need gameguard-client, you can use:

$ npm install gameguard-client

Note: The documentation for gameguard-client will not be covered here but you can head over to the gameguard-client documentation for client side usage.


To initialize GameGuard, you have to initialize it with a reference to a http or https server and an optional set of options.

param type description default
server http.Server A reference to the http server instance to bind to.
options Object
options.heartbeatInterval number The interval at which each player is pinged, in milliseconds. 30000
options.latencyCheckInterval number The interval at which each player's latency is calculated, in milliseconds. 5000
options.maxLatency number The maximum latency, in milliseconds, the player can have before being kicked. 300
options.mongodbConnectionString string The connection string to use to connect to mongodb. mongodb://localhost:27017


A basic example of initializing GameGuard this with my personal favorite http server, fastify, is as follows:

'use strict'
const path = require('path');
const fastify = require('fastify')({ logger: true });
const GameGuard = require('gameguard');
const gg = new GameGuard(fastify.server);
fastify.listen(3000, (err, address) => {
  if (err) throw err;`server listening on ${address}`);

Here's an example of initializaing GamGuard with options:

'use strict'
const path = require('path');
const fastify = require('fastify')({ logger: false });
const GameGuard = require('gameguard');
// Set the GameGuard server to use a latency check interval of 1000ms.
const gg = new GameGuard(fastify.server, { latencyCheckInterval: 1000 });
// Have the server listen on port 3000.
fastify.listen(3000, (err, address) => {
    if (err) throw err;
    console.log(`Listening on port 3000`);

Notice how we pass fastify's server instance to GameGuard so that GameGuard can use it to communicate with the client.

Let's also take a look how we can accomplish the same thing we did above but with express:

'use strict'
const path = require('path');
const express = require('express');
const GameGuard = require('gameguard');
const app = express();
// Have the server listen on port 3000.
const server = app.listen(3000, () => console.log('Listening on port 3000'));
// Set the GameGuard server to use a latency check interval of 1000ms.
const gg = new GameGuard(server, { latencyCheckInterval: 1000 });


Now let's talk about the operation of GameGuard:

  1. The GameGuard server instance is created with a http server instance.

  2. Now, the GameGuard server waits for a WebSocket connection from a page using the GameGuard client and in specific it waits for the client to send a message that contains the id of the player that connected.

  3. Before the client becomes a player, the GameGuard server checks to see if the id of that client corresponds to a player in the database that is banned and if so their connection gets reject. Otherwise, the client is accepted and their player profile is created locally and updated in the database.

  4. Everything is set up now. The player can be kicked, banned, messaged, or put into rooms.


Since GameGuard is not a linear app and it's hard to go in order with what to document, we'll just go over the general aspect of each part of GameGuard and then link to the documentation for that module that goes in detail about it.


The GameGuard server uses the MongoDB to manage players with the mongoose package to manage the schemas and other operations. The database connection info has a default value of mongodb://localhost:27017/gameguard but you can configure the connection credentials in a .env file with a sample connection file provided as .env.sample.

Check out the database documentation for more specific database operations.


At it's core, GameGuard works around watching for clients trying to connect to the server and turning those clients into players. Once connected, players can be interacted with in forms of messaging, kicking, banning, or placing in rooms.

Check out the player documentation for more specific player operations.


Rooms are used to group players together to perform similar actions together. For example, you can group players together in a room and easily send messages to all of them.

Check out the room documentation for more specific room operations.


There are a few actions in GameGuard that are global and affect all players connected to the GameGuard server regardless of the rooms they are in.

Check out the global documentation for more specific global operations.


To run the tests for GameGuard server, you can use:

$ npm run test



Package Sidebar


npm i gameguard

Weekly Downloads






Unpacked Size

143 kB

Total Files


Last publish


  • robert.corponoi