Learn How to Use TypeScript With Node.js and Express.js

Introduction to a typed RESTful API development experience

JavaScript is the language of choice when it comes to frontend development for the web. Advances in web development have led to the rise of multiple libraries and frameworks such as Vue, React, Angular, Svelte, and many others. A long time ago, JavaScript was seen as the language of the browser. However, this is no longer the case nowadays as we can use it for developing web applications and/or APIs ranging from small to large projects using Node.js and Express.js.

Having the ability to program backend and frontend using the same programming language is a big win. However, those with experience working with JavaScript know how ugly code can turn and how annoying it can be to detect small but impactful errors. One of the main reasons is due to the flexibility JavaScript offers by allowing dynamically typed variables that can change at runtime.

What do dynamically typed variables mean?

It means that if you create a variable named name, logically we could imagine the name stores a string value.

var name = 'Andres';

However, at any point in our code, we can assign the value of an object, array, number, or any other type of value available to name without the system throwing an error.

name = { first_name: 'Andres', last_name: 'Reales' };

Even experienced JavaScript developers have come across these kinds of situations, causing unexpected behavior throughout their projects. That’s why TypeScript was developed to put an end to these types of errors constantly found in JavaScript applications.

TypeScript has been received with good eyes throughout the JavaScript community, even to the point that some frameworks such as Angular support TypeScript. React and Vue provide TypeScript tooling support.

Can I use TypeScript with Backend Frameworks such as Express.js?

Fortunately for those of us who have worked with JavaScript on backend development, we can also use TypeScript making a smoother development process.

How to Setup TypeScript with Express.js?

The best way to explain how to have a regular setup to develop applications with Express.js using TypeScript is by working on a project. That’s why I decided to explain this process in a series of tutorials to get started with TypeScript for backend development split in the following topics:

Share this article or checkout our social media channels!