Part 2. Node.js + TypeScript API: Configuring Multiple Environments

Jesse Langford
2 min readSep 10, 2022
By kwanchaift

This is the second 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:

This installment will cover setting up multiple environments within your project. You can find the previous article here:

Improving startup

To improve our application startup, let's add three new packages

  1. nodemon: a tool for development that restarts your application when files change.
  2. npm-run-all: a CLI tool that enables you to run multiple npm scripts sequentially
  3. rimraf: the Node.js equivalent of rm -rf

yarn add nodemon npm-run-all rimraf -D

Once you have these we can change some of the scripts we created in part one.

change the scripts object in package.json to this:

clean: Makes sure our dist folder is empty before converting our typescript files to javascript.

tsc: command to run TypeScripts compile process.

run: runs the file we specified in our “main” entry.

build: a bundle of commands needed to build our project correctly.

start: a bundle of commands needed to start our server correctly.

start:dev: shorthand command to start the server

Multiple Environments

It’s likely you'll need to run your application in different environments. We can use the dotenv package to set that up.

yarn add dotenv