Part 1. Node.js + TypeScript API: Installation and Setup

Jesse Langford
3 min readSep 2, 2022
By VectorMine

This is the first installment in a series of guides showing how to create a Node.js + TypeScript API. The initial pieces will be very simple, but as we progress, I will be showing how to add features that would be expected in a production-quality API. You can find the repo for this project here: https://github.com/JWLangford/node-typescript-api.

You can also find a video walkthough here: https://youtu.be/SNAUpMJ4AWo

This installment will cover the installation and setup of the project.

Prerequisite Installs

Before going further, make sure you have these installed on your machine.

Nodejs
https://nodejs.org/en/
Command Check: node -vYarn
npm install -g yarn
Command Check: yarn -vTypescript
npm install -g typescript
Command Check: tsc -v

Getting Started

To get started, create the directory your API will inhabit.

mkdir node-typescript-api
cd node-typescript-api

Next, setup your project with yarn

yarn init -y

This will add a package.json file to your directory.

Dependencies

We’re going to need three external packages to get started.

  1. typescript: This package enables us to use types and type checks in our codebase
  2. express: This package is a minimal and flexible Node.js web application framework
  3. @types/express: This package contains types for the exported modules within the express package.
yarn add typescript @types/express -Dyarn add express

TypeScript Config

The next thing we need to do is configure TypeScript for our project. Run the following command inside the root folder of your project.

tsc -init

This will add a tsconfig.json file to your project. Go into the file and uncomment and update the outDir field.

--

--