Multiplayer Game Development with TypeScript, Phaser, Socket.io, and MongoDB
Game data rarely looks the same for very long. A player document might start out with just a username and a score, and a few sprints later, it needs an inventory, a set of unlocked achievements, and a friends list, each shaped differently from the last. MongoDB's document model is a natural fit for that kind of growth, since a new field is just a new field, with no migration to write and no join to add. A match record can embed both players directly, scores and all, so reading back a finished match is a single document lookup rather than a query spread across multiple tables. Atomic operators like $inc and $max also mean stats and high scores can be updated safely by many concurrent players at once, without the application code having to coordinate a read-then-write itself.
In this tutorial, we're going to build a simple multiplayer game. Each player controls a white square on a canvas, and for thirty seconds, yellow coin squares spawn at random positions. Whoever collects the most coins when the timer runs out wins. Movement, coin spawning, and scoring all happen over WebSockets through Socket.io, with the server acting as the single source of truth for everything that happens during a match. MongoDB sits underneath that, storing player accounts, match records, and the leaderboard.
We'll use TypeScript, Zod, Socket.io, and Express on the backend, and Phaser, TypeScript, and Socket.io on the frontend. The MongoDB Node.js driver is used directly, without an ODM like Mongoose, so every query in this tutorial is plain driver code. If you'd rather skip ahead or just want to run the finished project, the full source is available on GitHub.
Read MoreResty Desktop, a GUI for the Restic Backup Application
There are quite a few backup applications in circulation, each with their own set of benefits. I have personally become very fond of the Restic backup application because of it being quick, reliable, and open source.
Typically when I use Restic on my server I'm using Backrest, like demonstrated in a previous tutorial. When I am on my desktop I use the CLI, but often find it cumbersome to remember the commands, paths to my backups, etc.
This brought me to the creation of Resty Desktop, a GUI wrapper to the official Restic CLI application!
Read MoreTest Password Strength and Password History with TypeScript and MongoDB
Just about every application you build is going to need some form of user authentication, and the moment you have user accounts, you have passwords to manage. Storing them safely is only part of the job. You also need to make sure those passwords are strong enough to be worth protecting in the first place, and in many cases, you need to make sure the same password isn't recycled every time it’s rotated.
Password reuse is a bigger deal than it sounds. Compliance frameworks frequently require that the last several passwords cannot be used again, and even outside of compliance, it is good hygiene. If a password leaks today and a user just rotates back to it six months from now, your rotation policy did not actually protect anyone.
MongoDB happens to be a really good fit for this kind of feature. A user document can store the current password hash at the root of the document, along with a growing array of previous hashes, all in the same record. There is no separate join table to set up and no migration to run when a user changes their password for the tenth time.
In this tutorial, we'll see how to build a small TypeScript API using Express Framework, Zod, and the MongoDB Node.js driver. This application registers users with strong password rules, authenticates them, and rejects any password change that has been seen before.
Read MoreExtract Text from Your PDF and Image Files with Apache Tika
With AI becoming increasingly popular in everything, and retrieval-augmented generation (RAG) becoming a requirement in everyone's organization, how you're providing context to the AI tools becomes important.
Some of the more popular subscription model tools like ChatGPT accept images and files in the prompts, at which point it can decipher what's in those files, but many of the local models and tools can only work with plaintext.
There have been a few personal scenarios where I've needed to work with PDFs in my AI tools. Such examples include:
- The LiveKit voice agent demo I created that accepts resumes and job descriptions in any document format.
- The self-hosted Open WebUI chat tool that lets the user create a knowledgebase from various document formats.
So how do we make it work?
Take a look at Apache Tika, an open source tool that extracts metadata and text from popular file formats and returns it as plaintext. In this short tutorial, we're going to see how to deploy Apache Tika and watch it work its magic.
Read MoreHow to Install MongoDB on Ubuntu: A Step-by-Step Guide for Beginners
So you're ready to dabble with MongoDB on Linux and you've chosen Ubuntu as the variant you want to work with. Fantastic choice because you're in for a fairly easy experience that will get you up and running with MongoDB in no time!
In this tutorial, we'll explore installing MongoDB through the Ubuntu Package Manager and do some minor quality of life improvements that will better secure your installation from the rest of the world. While we'll be exploring the native installation experience, if you'd prefer to use Docker on Ubuntu for working with MongoDB, check out my previous tutorial, Running MongoDB in Docker - A Complete Guide with Examples.
Read MoreRunning MongoDB in Docker - A Complete Guide with Examples
So you're looking to self-host MongoDB or start dabbling with it in a local setting? There are a few options to get started if you don't want to jump directly into MongoDB Atlas, one of those options being containers with Docker. Making use of Docker is a solid choice when managing your MongoDB instance because it doesn't take more than a minute to do and it is easy to maintain or move between host computers.
In this article, we're going to see a few approaches toward deploying MongoDB with Docker and explore a few tips and tricks along the way.
Read MoreHow to Design Nested Documents for a Blogging App
So you want to build your own content management system (CMS), also sometimes known as a blog? This is a classic example when learning how to use a database, whether it be a relational database management system (RDBMS) or a NoSQL database, because it explores a potentially large amount of data as well as relationships in that data. The example of a blogging app also translates well for other data modeling needs.
In this article, we're going to explore some do's and don'ts when it comes to designing your NoSQL documents in MongoDB. However, we won't actually be developing a blogging app, only looking at things from a data perspective.
Read MoreSearch
Recent Posts
- Multiplayer Game Development with TypeScript, Phaser, Socket.io, and MongoDB
- Resty Desktop, a GUI for the Restic Backup Application
- Test Password Strength and Password History with TypeScript and MongoDB
- Extract Text from Your PDF and Image Files with Apache Tika
- How to Install MongoDB on Ubuntu: A Step-by-Step Guide for Beginners