Does your JavaScript project validate inputs using Joi or a similar schema validator? Do you want to declare types using more-standard TypeScript without forcing your users to switch to TypeScript?

Unfortunately, you can’t. The industry is moving to TypeScript, preferring static typing over runtime validation because it’s more efficient. Validation is expensive, so only use it when you need it.

If your users want the benefits of TypeScript, such as a better IDE experience and fewer bugs, they will need to install typescript as a dev dependency and make a few additional tweaks to their project. …

Publishing to NPM? Use Peer Dependencies!

If you publish to npm, you probably know that you should specify peer instead of regular dependencies.

It appears that most publishers didn’t get the memo. Why not? Before version 7, the npm CLI essentially rendered peer dependencies unusable.

Upgrade to npm 7 and change the world for the better!

Here are some suggestions:

2. When referencing a package that has several actively maintained major versions, list each compatible version…

Writing a script (e.g., for db-migrate) that creates MySQL users is not as easy as it sounds when you want to leverage AWS RDS IAM passwordless security. If you develop locally and deploy to RDS MySQL, the script needs to create users on both flavors of MySQL. Here’s one way to do it.

A million tiny c̶u̶t̶s̶ decisions

Image for post
Image for post

Decisions, decisions

Building a browser app in React can be intimidating. Developers must make many decisions just to get basic functionality up and running, including (my choices are in parens):

I started this project in November 2020 and subsequently r̶e̶w̶r̶o̶t̶e̶ refactored it w̶a̶y̶ ̶t̶o̶o̶ ̶m̶a̶n̶y̶ several times into something that I was satisfied with. It…

Applications created by create-react-app (CRA) include an Express-based proxy for working around cross-origin security in web browsers. This capability is described in Proxying API Requests in Development.

The CRA-provided proxy works well for static host names. However, if the URL (particularly the host name) of an external service depends upon data acquired at runtime, you will need to do some extra work.

Why would you need dynamic host names? You shouldn’t in most cases. But if your application needs to, say, choose from a list of geographically distributed hosts based on input data, you need a more permissive proxy.


VSCode’s git integration is excellent, especially when combined with the GitLens extension. VSCode has become my primary git tool.

However, as of December 2020, as far as I can tell, VSCode’s git integration relies on environment variables. So here’s a script I use to configure my git settings and start VSCode on OSX and Linux. Unfortunately, you can’t switch git identities within a VSCode instance.

This script requires your git account to be configured with an SSH public key.

To use this script and continue using git from the same shell session with the same configuration, ‘source’ it via ‘source…

This post explains how to configure Prettier and ESLint with minimum effort to achieve the following via the command line an in Visual Studio Code:


This example assumes that Typescript is only used in files that have the extensions .ts and .tsx.

This example overrides the maximum line length rule to allow up to 100 characters, but you can remove or modify it.

This example allows JavaScript files (*.js) …

The functions in the async package that implement sequential function execution, such as waterfall and eachSeries, accept an array of functions. The provided functions execute sequentially in array order.

Each function in the array accepts another function as their last argument. This parameter is typically named next. The next function accepts a truthy value indicating whether an error occurred. Passing a falsey value to next causes the next function in the array to be invoked. Passing a truthy value to next terminates to call chain.


Avoid passing next to an external function as a callback parameter!

Although it’s…

JavaScript doesn’t provide a way to cancel long-running background tasks. However, it is possible to simulate this feature using Promises.

First, create a Promise. Inside the Promise’s constructor callback:

a) Stop the timer

b) Call resolve() or reject()

Of course, there’s a problem: after the timeout, the function keeps executing. In order to stop the task after the timeout expires, you will need to devise your own solution. …

Let’s say you’re implementing the requirement that rows should never be deleted from particular tables in a relational database. Perhaps this is a requirement from regulators. Or maybe the schema declares foreign key constraints (and — yes! — it should, at least in dev environments) but, for reasons such as performance and safety, without cascading deletes.

You’re not trying to use the RDBMS to store an audit trail of every modification, which is usually a bad idea, but you don’t want data to completely disappear, either.

What’s the best way to virtually delete (or deactivate) rows in a RDBMS?


Terris Linenbach

He/him. Coder and gamer since 1980. Lately I’ve been coding in Node and React. Always seeking The Best Way.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store