I’ve been enjoying using Knex.js database client for quite some time when implementing GraphQL API backends. One thing that it currently lucks though, is the ability to generate strongly typed (TypeScript) models from the actual database schema.

Luckily, there is a solution! Assuming you have a database table that looks like this (Knex migration):

await db.raw(`
AS TEXT CHECK(VALUE ~ '^[0-9a-z]{6}$')`);
await db.raw(`
CREATE TYPE user_role
AS ENUM ('consumer', 'provider')`);
await db.schema.createTable("user", (table) => {
table.specificType("id", "short_id").notNullable().primary();
table.specificType("email", "citext").unique();
table.specificType("role", "user_role").notNullable();
table.timestamps(false, true);

Having User (class) and UserRole (enum) data models in place, you…

When it comes to user input validation, particularly when designing (RESTful, GraphQL) APIs, it’s important to have these objectives in mind:

  • Validator needs to support various data types such as emails, mobile phone numbers in different locales, credit cards, etc. Well tested and already used in production by many companies.
  • It needs to have an API (interface) that allows writing validation rules with the minimum amount of boilerplate code.
  • This interface needs to be strongly typed, allowing a better development experience (DX) when used with TypeScript.

I think validator.js (✭17k) fits perfectly into the first requirement. And, in order to…

Google Cloud SQL, PostgreSQL Edition

When creating a new Cloud SQL instance…

Ensure that the instance name is picked wisely. You may find it helpful if it remains short, and contains the Cloud SQL edition (MySQL, PostgreSQL, SQL Server) and version number. For example, pg12.

There might be some confusion regarding using NODE_ENV variable in Node.js apps. A few things you need to be aware of:

(1) Do not set NODE_ENV to anything other than production, development or test.

When you deploy your app to let’s say Google Cloud Functions, the NODE_ENV variable will always be set to production, you will not be able to override it.

Similarly, when you run unit tests, the NODE_ENV variable will always be set to test by the test runner (this is a good default value that you don't want to mess around with, too many tools depend on…

If you normally start building your swing- or day-trading watchlist starting from tech analysis, here is a good tool that can help you accelerate this process.

Step 1: Decide which stocks or other financial instruments to trade

For example, in the case with swing trading, you may prefer stocks of large companies with predictable volatility and noticeable up or downtrends.

Step 2: Open this list on the watchlist.io website and scroll through the charts

See S&P 500 Companies list as an example.


Step 3: Mark charts with patterns that you’re already familiar with as favorites

Step 4: Save your “Favorites”…

React with/without Redux

As you probably know React.js provides us with these two helpful hooks — React.useReducer() and React.useContext(). You may think that combining them in a creative fashion would give you a perfect replacement for Redux? Not so fast :)

First, let’s see what’s the problem with Context-based implementation and how it may look like:

import React from 'react';const initialState = { ... };function reduce(state, action) { ... }const ReducerContext = React.createContext();function useGlobalReducer() {
return React.useContext(ReducerContext);
function App() {
const reducer = React.useReducer(reduce, initialState);

return (
<ReducerContext.Provider value={reducer}>
<Example />
function Example() { const…

With Facebook Customer Chat widget you’re now able to connect with your website visitors (customers) even after they left your site. How cool is that ;)

View source code at https://github.com/kriasoft/react-firebase-starter

You start by creating a Facebook Page for your app or product. Find your Page ID in the About section — you will need that for the widget. Then go to Page Settings > Messenger Platform and whitelist your domain name, otherwise, the widget won’t show up on your site after integrating it.

The widget itself can be integrated by injecting Customer Chat SDK script into your React.js …

Have you noticed this trend that many JavaScript developers don’t know how to solve pretty basic tasks in their web apps without using Redux?

It starts like this — a developer has two or more components in different parts of the UI and struggling to organize a communication channel between them. That’s the exact problem that Redux is great at solving, right? Well, it depends…

What if you’re app is using a Firebase or GraphQL client (Relay Modern), that already handling data management for you? All you have to do in this case is just to fetch new data from…

First of all, big thanks to Facebook developers for open sourcing and maintaining GraphQL.js library. It can’t express how well it works for me and my team (BTW, we’re hiring) and I like really how simple yet flexible it is. As Albert Einstein once said:

Everything should be as simple as it can be, but not simpler.

Below you can find a couple of code recipes demonstrating how to throw custom errors as well as log errors in an API project powered by Node.js (v8 or newer), JavaScript (using Babel compiler) and GraphQL.js.

Let’s assume, that you have videos top-level…

It might be NOT that hard as you think! Let’s see you can you can call C/C++ code or use a native library from a Node.js app.

Node.js ❤ C/C++

Q: Why would I need to call C/C++ code? There is half a million NPM modules, why would I need native stuff at all?

A: It you don’t need any C/C++ interop right now, it doesn’t mean you won’t need it in the future. …

Konstantin Tarkus

Bringing the technical edge to early-stage companies with advice on software architecture, best practices, database design, web infrastructure, and DevOps.

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