Build a REST API with Node.js, TypeScript & MongoDB

Tom Nagle
6 min readMay 9, 2021

Update: The video for this guide has been updated

Please watch the updated version of the video instead, it’s much better.

In this guide, we are going to build a REST API with Node.js, TypeScript, and MongoDB. This guide is for junior to mid-level developers that want to build APIs like a senior developer.

Finished repository:

Postman collection:

Note: This guide uses commands like mkdir and touch. For those that are unfamiliar, mkdir will make a new directory and touch will create a new file. These commands will work on a Mac or Linux OS, but will not work on a Windows machine as far as I’m aware.

Note 2: For the best learning outcome, watch the video above and follow along. Use this article for support when you miss a snippet of code.

Technologies and concepts covered:

  • JWTs & refresh tokens
  • Node.js
  • TypeScript
  • MongoDB with Mongoose

Why should you learn how to build a REST API in 2021? Isn’t it all about GraphQL now?

  • REST APIs are still a staple of the web development industry
  • Microservices architectures take advantage of REST
  • You need to know how REST APIs work even if you’re a front-end developer

Bootstrap the application

Start in an empty directory and create and initialize a new Node.js application

yarn init 

Initialize the TypeScript project

npx typescript --init

Create a nodemon.json file and add the following code:

Tom Nagle

I am a full stack JavaScript developer, living in Melbourne, Australia. My preferred stack is Mongoose, TypeScript, Node.js, React & GraphQL.