Happy holidays developers ? Recently, I published Matterhorn ?, an API boilerplate project built with Node.js and TypeScript. The API server uses Fastify, a fast and low overhead web framework. The project comes with a configured type system (TypeScript), test runner (Jest), linter (TSLint), and even a CI pipeline (Azure DevOps).
This article will give a brief overview of the project and insights into certain design decisions.
An API boilerplate project built on Node.js and TypeScript ? - Ethan-Arrowood/matterhorngithub.com
? Psst! This overview section is very similar to the project docs on GitHub
Get started quickly by following these steps:
- ? Fork the repository
- ?♀️ Clone it to your computer
- ?♀️ Run n
pm run install && npm run dev
- ? Edit any of the files in s
- ? Watch as the app magically rebuilds and relaunches itself
✨ That’s it for the basic user guide. Now let’s dive into some of the commands available to you by default. All of the commands below can be run with
npm run <script> . This project makes use of npm mo
n and rimraf to enable platform agnostic npm scripts.
build— build the TypeScript files and output to
build:watch— automatically rebuild files if changes are detected in
clean— recursively delete the
clean:build— recursively delete the
clean:coverage— recursively delete the
coverage— run the test suite and generate code coverage reports
npm run coveragethen open the results in a browser
dev— concurrently run
lint— run the linter configured by TSLint on the
start— run the app from
lib/. Make sure to use
npm run buildfirst!
start:watch— relaunch the server if new changes are detected in
test— run unit tests defined in the
test:ci— run unit tests and generate necessary files for CI integration
Command Line Arguments & Environment Variables
Matterhorn implements example usage of both command line arguments and environment variables. It uses
yargs-parser to manage command line arguments. Command line arguments are passed in through the start command:
node lib/index.js <command line arguments>.
--log argument has been enabled as an example. Running
npm run start starts up the project without any command line arguments. This command is intended to be used in production, so logging is disabled by default (i.e. we don’t pass the
If you are using this command to test your code locally and want to see the logging output, then run
npm run start —- -—log. This passes the command line argument through npm and into the aliased command.
Environment variables work in a similar way to command line arguments. They can be set in multiple ways depending on the terminal and operating system you are using. In a bash terminal you can specify environment variables as you use any of the above mentioned scripts by prepending the assignment to the command.
For example, this project has the
PORT environment variable enabled. In a bash terminal run
PORT=8080 npm run start to run the API on port 8080.
I built this project because I found myself constantly copying and pasting config files for new Node.js projects. I love what the
create-react-app team has accomplished and envision Matterhorn developing into a similar kind of tool. Down the road, I look forward to developing a complete CLI to help developers get up and running with Node.js and TypeScript even quicker.
Matterhorn is an opinionated project. The build and linting systems are configured to my preferences, but are very easy to change. For example, in
tslint.json I defined the
"semicolon" rule as
false — to enforce semicolon usage throughout the app, change this to
Additionally, this project contains an
azure-pipelines.yml file. This defines the CI (continuous integration) pipeline on Azure DevOps, a robust tool offered by Microsoft to enable teams to plan smarter, collaborate better, and ship faster with a set of modern dev services. This was another opinionated decision due to my experience with the tool. There are many other great CI options such as Travis CI or Circle CI that I hope to support in the future.
Hope you enjoy!
Thank you for taking the time to read this article and checking out Matterhorn ?. The project is open sourced, and I encourage developers of any skill level to come contribute. Check it out on GitHub and if you want to hear about future updates as well as other things I develop follow me on Twitter.
Best wishes ? ~ Ethan Arrowood