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
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..
- Joi for input validation. Alternatively Middy Validator with JSON Schema.
- Luxon for date/time. Built by one of MomentJS authors, Luxon can be thought of as an immutable successor of MomentJS. We have switched from MomentJS to Luxon & it's been a breeze: many hiccups due to mutability of MomentJS are gone.
- got for HTTP requests. This comparison with other libs is nice.
- big for fixed-precision calculations.
- jest for testing.
- middy for various AWS Lambda middlewares.
- lodash for functional programming, but also You-Dont-Need-Lodash-Underscore
However, there is a tradeoff of using big JS libraries, such as lodash: they could propell the cold-start problem in AWS Lambdas.
const zipCode = chargePoint && chargePoint.address && chargePoint.address.zipCode
we can write
const zipCode = chargePoint?.address?.zipCode
?.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.
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.
If you need help with building the tech products get in touch.