TypeScript for Node

Hello!

Paul Shannon

Topics

  • Why TypeScript?
  • TypeScript & Node tools
  • Writing backends

But before I tell you that story

I have to tell this one...

Demo Project for Today:

I'm Right

Why TypeScript?

Better development is about creating faster feedback

Benefits

  • Provides (optional) static typing
  • Improved integration w/ IDEs
  • Continually improving code quality

				public function sample(): string {
					// Some really long function
					// 200 lines...
					if (Math.random() > 0.99) {
						return; // whoops!
					}
					// 200 lines...
				}
			

Types ensure you fail during design time

instead of production

TypeScript & Node

How do we iterate faster?

ts-node

A CLI and execution environment that automatically compiles TypeScript files

nodemon

Watches for changes and automatically restarts applications and processes

ts-node and nodemon together

=

Zero compilation restart on save

How do we debug?

ts-node supports debugging and source maps too!

Building backends with TypeScript

NestJS

A Node server framework written in TypeScript

Features

  • Authored in TypeScript
  • Built on top of Express
  • modern language features like async/await
  • decorators to reduce cruft

Controller

Handles routes & HTTP requests for the application

Providers

Typically hold and mutate state to be injected

Module

Provides metadata about the structure of a feature

Solutions For

  • Authentication
  • Persistence
  • Uploading files
  • Validation
  • Logging
  • Security
  • GraphQL
  • Websockets

Other features

  • Nest CLI
  • Middlewares
  • Exception filters
  • Pipes
  • Guards
  • Interceptors
  • Custom Decorators

TypeORM

ORM written in TypeScript for node

Features

  • Authored in TypeScript
  • Decorators remove boilerplate
  • Active Record & Data Mapper patterns
  • Entity and Column support
  • Relations
  • Query builder
  • Migration support

More tools

  • prettier
  • eslint
  • Postman
  • Docker

Questions?