A Simple Node.js Boilerplate With TypeScript

Using create-nodejs-ts to set up new projects quickly

Vitor Hugo Salgado
2 min readJul 21, 2021
Photo by Safar Safarov on Unsplash

Hello developers, greetings from Santiago 🇨🇱. This is my first post here, and I want to present an NPM package I recently published, create-nodejs-ts.

Suppose you want to start a new project with a healthy and consistent development environment. In that case, there are several configurations you may need to do, like setting up “linters,” code style tools, test frameworks, git hooks, etc. create-nodejs-ts comes with all those boring stuff already configured so you can focus on the fun stuff, coding.
The idea is very similar to scripts like create-react-app.
Below I will briefly explain how to use and the tooling contained in this boilerplate.

The GitHub project contains more details :)

Starting a New Project

It is easy to use this boilerplate, just a command, and done! The preferred way to use the package is with npx. Take a look at the sample below:

npx create-nodejs-ts --no --app=new-app

The command above will create a new Node.js project on the folder new-app in the current directory. You can omit the argument app; the new project will be created on my-app. You can use npm init too:

npm init nodejs-ts --app=new-app

This boilerplate focus on tools that are usually common on Node.js projects. For now, there’s no boilerplate for an HTTP server or stuff like that. That’s not the idea of this project.
Run the script and start coding with your preferred libraries.

The generated boilerplate will look like this:

Generated Project Structure

Tooling

These are the tools already configured on this boilerplate:

ESLint and Prettier ensure code style and good practices.
Husky, Lint Staged, and Commit Lint ensures that no files are committed without following project standards.
Jest is the test framework and comes with ts-jest for TypeScript.
Nodemon is used to reload the application on changes.
Docker is used for local development, and it comes with a Dockerfile that generates a minimum image with gcr.io/distroless/nodejs.

Take a look at the source code on https://github.com/vitorsalgado/create-nodejs-ts repository if you want to know more details.

Thanks for reading, and I hope you enjoy :)

--

--

Vitor Hugo Salgado

Software Engineer from Sao Paulo 🇧🇷 based in Berlin 🇩🇪