Develop in Docker: Node.js, Express, & PostgreSQL on Heroku

This post builds on the excellent tutorial from Tania Rascia: Create and Deploy a Node.js, Express, & PostgreSQL REST API. I want to build a little web app that can store some data! …without installing anything new on my computer. Here’s how to configure VSCode Remote Containers to do that. Installed on my machine: Docker … Read moreDevelop in Docker: Node.js, Express, & PostgreSQL on Heroku

Read a file with promises in TypeScript on Node

import * as fs from “fs”; import { promisify } from “util”; const content: Promise<string> = promisify(fs.readFile)(“path/to/the/file”, { encoding: “UTF-8” }) I am tired of looking that up over and over every time I want to read a file into a promise in Node using TypeScript, so here it is. Next time, bring me here, Google. The promisify call turns fs.readFile from a callback-based method to a promise-based one. promisify accepts … Read moreRead a file with promises in TypeScript on Node

Do Things Right with npm install

Lately I’ve been wrestling with npm. Here are some rules I’ve learned: Use `npm ci` rather than `npm install` `npm ci` will bring down exactly the dependencies specified in package-lock.json. `npm install` does more than that; it also tries to update some libraries to a more recent version. Sometimes it updates URLs or nonsense in … Read moreDo Things Right with npm install

Reference: Typescript asynchronous sleep that returns a promise

I want some code to execute after a delay. I want to do this with promises, in TypeScript, asynchronously. Apparently this is hard. Here is the spell: const sleepPlease: (number) => Promise<void> =     promisify( (a, b) => setTimeout(b, a)); const slow: Promise<string> =     sleepPlease(500).then(() => “yay finally”);I imported promisify from “util”. setTimeout is … Read moreReference: Typescript asynchronous sleep that returns a promise

Bring the data to the code, or the code to the data?

Object-oriented code was conceived as message-passing between objects. Service-oriented architecture emphasizes delegation to another system. The entire web is a whole bunch of requests flying around. There is one clear way to be efficient about this: stop waiting for results. When we’re writing imperative code, we want to write the operations in the order they … Read moreBring the data to the code, or the code to the data?

starting to maybe get the point of node.js

Listening to Glenn Block talk about node.js at Technology and Friends, there’s something interesting about the philosophy behind node.js. Threads are hard. Threads include overhead, but more significantly, using them requires the developer to hold more stuff in his head. Node.js has a philosophy that leads to asynchronous processing without multiple threads. Glenn explains how … Read morestarting to maybe get the point of node.js