Our great sponsors
-
hdb-typescript-best-practices
Repository to showcase the best practices with TypeScript using HarperDB
-
SurveyJS
Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
This repository is located at the HarperDB Community GitHub. You can clone it and follow along with the article. We'll be using the cloud version of the database but, in the repository, you'll find a docker-compose.yml file that you can use to run it locally with docker compose up.
To use TypeScript you need Node.js installed, be sure to use the latest LTS version. You can check it by running node -v in your terminal. If you don't have it installed, you can download it here, or use a version manager like asdf, nvm, or even volta.
For this we will need to create a schema that we can compare and validate our object against, this is the perfect use case for Zod! Zod is a TypeScript-first schema validation library that allows us to create schemas and validate our objects against them. Let's install it by running npm install --save zod.
To use TypeScript you need Node.js installed, be sure to use the latest LTS version. You can check it by running node -v in your terminal. If you don't have it installed, you can download it here, or use a version manager like asdf, nvm, or even volta.
{ "name": "hdb-typescript-best-practices", "version": "0.0.1", "description": "", "main": "index.js", "type": "module", "scripts": { "start": "node --env-file=.env dist/index.js", "start:dev": "NODE_OPTIONS='--loader=tsx' node --env-file=.env src/index.ts" }, "keywords": [], "author": "Lucas Santos (https://lsantos.dev/)", "license": "GPL-3.0", "devDependencies": { "@types/node": "^20.7.1", "tsx": "^3.13.0", "typescript": "^5.2.2" } }
Usually we use a web framework to avoid having to recreate everything. In this example we'll use a very fast framework called Hono, just to be away from Express for a while.
Usually we use a web framework to avoid having to recreate everything. In this example we'll use a very fast framework called Hono, just to be away from Express for a while.