I suck at puns.

Node is a Javascript server. Out of the box it does nothing, instead relying on the developer to write onboarding code to give the server functionality. Many Discord bots are written using Node, and it can be used to serve web pages as a small-footprint web server. Because Node is, as they say, unopinionated, a lot of the functionality can be had by installing library packages from a service called NPM — Node Package Manager. This is a public repository that developers can access, download from, and upload to, and it’s a godsend for working with Node (and React and other similar technologies).

You might have Node installed right now and not even know it. Being that it’s portable and cross-platform, I’ve been seeing a few applications starting to bundle Node with their installer as a prerequisite. Once it’s installed, though, it’s usually universally available, and anyone can write anything for it with only a few lines of code.

For this project, I had to install two packages for Node: Express and Colyseus.

Express is a basic web server. Web servers serve web pages. A web page is basically just a string of text read from a file. A browser requests a file based on routing, which is the understanding that a server has about a path designated by a URL that lead to a particular file that the server houses. The server responds by streaming the text of that file to the browser. The browser then parses the text and formats the output to the window based on the HTML tags and CSS classes and attributes. If Javascript is included, then the browser will execute that code. Express handles the routing and also handles headers, which is meta-information that acts as a not-so-secret handshake between the browser and the server. Express is important here because the server will be taking requests to specific endpoints (defined via routing) and returning text in the form of JSON — JavaScript Object Notation, a formalized format for describing and transporting data.

Colyseus is designed as a game server library for Javascript-based systems. Game servers (from what I understand) require two features at the very least: an always-open line of communication with a client, and a regular update cycle called the “game loop”. The game loop fires several times each second, which is where we get the vernacular “frames per second” (fps). In a 60fps scenario, the game will update 60 times per second. During each refresh, the game server runs code which reconciles input from the client with it’s own logic against data and returns the results to any client who needs to hear it through that always-open line of communication. In much larger, fancier games, this communication is probably done through low-level networking protocols which actually underpin the web sockets that Colyseus uses, but Colyseus obfuscates that technobabble gives us the easy to use paradigms of messages and events.

Well, that’s all I have to say about that. Surprised? So am I. Let’s get a beer.


Owner and author.

Leave a Reply

Your email address will not be published. Required fields are marked *