Things I'm learning about Typescript & NodeJS with AWS Lambdas

I'm now working on a project which uses Typescript & NodeJS with AWS Lambdas. Typescript is new to me, so I thought I will keep a note for interesting stuff I have learned about Typescript/NodeJS ecosystem.

Managing NodeJS versions with nvm

NodeJS comes with different versions. Each version bundles the npm as well. For example, NodeJS v15 comes with NPM v7, while NodeJS v14 comes with NPM v6. Here's an overview.

When working on multiple projects, it's handy to switch between multiple NodeJS versions. That's when nvm comes into play. nvm also supports .nvmrc to further automate the switching..

Handy libraries

However, there is a tradeoff of using big JS libraries, such as lodash: they could propell the cold-start problem in AWS Lambdas.

Optional chaining

There's a handy syntactic sugar introduced in Typescript 3.7 called optional chaining.

Instead of

const zipCode = 
  chargePoint && chargePoint.address  && chargePoint.address.zipCode 

we can write

const zipCode = chargePoint?.address?.zipCode

That's useful.

The ?. operator functions similarly to the . chaining operator, except that instead of causing an error if a reference is nullish (null or undefined), the expression short-circuits with a return value of undefined.

MDN Web docs

jest --watch

It turns out that jest has a watch mode: tests are rerun automatically on code change. That a nice speed up, especially in combination with tests selection.

Twitter accounts


If you need help with building the tech products get in touch.