Open-sourcing an Express boilerplate & CLI

I decided it was finally time to make one boilerplate to rule them all and from then on use that for every project going forwards.

With an endless list of side projects, each using their own version of an express app with different features and concepts, I decided it was finally time to make one boilerplate to rule them all and from then on use that for every project going forwards.
But what is it that an boilerplate needs to order to make it useful for each project? To answer that, I’ve wrote a small list of actions I’d take to get an API up and running.
  • Run npx express-generator
  • Install necessary packages; jsonwebtokens / mongoose / cors / uniqid etc.
  • Setup a User mongoose model
  • Setup authentication routes, usually by copy/pasting code from previous projects.
  • Setup sending emails via a third-party mail api and test Magic link emails.
  • Test the auth routes by posting to /auth/signup
 
Much of the code I use per project is the same, just copied and pasted from a previous project and modified to fit the current project or improved/refactored in some way.
 
For example, I recently changed how I interact with a MongoDB database, removing the need to create a service file per model.
Eventually this got me thinking about creating a boilerplate that I could clone from a repository and skip having to do a bunch of repetitive actions so I sat down one weekend and started building. By the end of the weekend, I had a simple API boilerplate with a basic features like Authentication ready to go, and a few fancy features like validation middleware and checking the config file is correct.
 
Because I couldn’t think of a better name yet, I simply named it Diamond Express and it’s available for anyone to use and improve at:
 
It’s current features are:
  • Written in Typescript
  • config.ts validation
  • Validation middleware with Yup
  • Mongoose Models are automatically loaded
  • Uses a passwordless "magic email" authentication system
  • services/librarian.ts for full control of Records in a MongoDB database
 
I plan on adding more to this over time as projects grow and more features are needed “out of the box”.
 
Every Boilerplate needs a CLI” - Spiderman, or something
 
In addition to the boilerplate, I started writing a CLI tool to aid in the building of APIs, so far it’s pretty simple and only has a handful of commands for cloning the repository to a folder, generating a UUID and describing the current environment, a command inspired by Laravel’s new About command. In the future, I aim to add a few commands for generating routes and controllers as well as being able to manipulate data in a database too. You can grab the the CLI, unsurprisingly named Diamond CLI, here: