loading...
Cover image for A Dockerized Nodejs Express Boilerplate with TypeScript

A Dockerized Nodejs Express Boilerplate with TypeScript

sidhantpanda profile image Sidhant Panda Originally published at Medium ・2 min read

Github Project: https://github.com/sidhantpanda/docker-express-typescript-boilerplate

Getting started with TypeScript for your next backend project? Or just want to play around with a TypeScript based Express server? This project’s for you!

Microsoft already has a starter repo. Why this?

There is Microsoft’s starter repo but it requires you to install a bunch of other stuff like MongoDB yourself. The Microsoft repo is a good reference repository but lacks a lot of stuff when building production applications.

How to get started?

Simple, just run:

$ bash <(curl -s https://raw.githubusercontent.com/sidhantpanda/public/master/scripts/generate-express-ts-app.sh)

Or, if you don’t trust the shell script, clone the repo:

$ git clone git@github.com:sidhantpanda/docker-express-typescript-boilerplate.git your-app-name

Features

  • You can spin up Mongo containers and run your Node project with nodemon with a single command, and spin them down when you are done. Just run the following command and see it happening:
$ npm run dev

Running the above commands results in

  • 🌏API Server running at http://localhost:3000
  • ⚙️Swagger UI at http://localhost:3000/dev/api-docs
  • 🛢️MongoDB running at mongodb://localhost:27017

Pressing Ctrl + c will stop the server and remove all mongo containers. All the data in Mongo is persisted between the runs at data/dev/mongo .

  • This project also contains instructions to dockerize your application from the get go, so you get to learn Docker along with it, or experienced developers can directly start configuring the Dockerfile or docker-compose.yml files.

  • A custom middleware for easier async/await for your request handlers. This allows you to write less verbose and eliminate having to write try-catch blocks in your request handlers every time you want to write an async method. Just throw any error and the handler will catch it and pass it on to the Express error handler.

  • Sample mongoose model written in TypeScript. Lets you kick-start data modelling.

  • Comes with a sample Open API 3.0 spec file so you can get started with API documentation directly.

  • All configuration done through .env file.

  • ESLint + Prettier — Linting and formatting from the start

  • Winston as the default logger to generate debug and error log files during application lifetime.

  • Pre-configured Travis CI for that automation goodness.

Posted on by:

sidhantpanda profile

Sidhant Panda

@sidhantpanda

A small developer fish in the developer ocean

Discussion

markdown guide