npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@inteli.city/node-red-contrib-postgres-async-pg

v1.0.1

Published

Node-RED node for async PostgreSQL query execution with concurrency control and Nunjucks templating

Readme

async.pg — Node-RED PostgreSQL Async Node

A Node-RED node for executing PostgreSQL queries with controlled concurrency and Nunjucks templating.


Index

  1. Overview
  2. Features
  3. Installation
  4. Configuration
  5. Usage
  6. Templating (Nunjucks)
  7. Concurrency Model
  8. Message Flow
  9. Status Indicator
  10. Error Handling
  11. Design Principles

1. Overview

async.pg executes a SQL query for each incoming message.

It is designed to:

  • control database concurrency
  • avoid hidden queues
  • provide predictable execution

2. Features

  • Asynchronous query execution
  • Configurable concurrency limit
  • Internal FIFO queue
  • Nunjucks-based SQL templating
  • PostgreSQL connection pooling (aligned with concurrency)
  • Real-time execution status

3. Installation

npm install @inteli.city/node-red-contrib-postgres-async-pg

Or via the Node-RED palette manager, search for async-pg.


4. Configuration

Database config node (postgresDB)

| Field | Description | Default | |----------|-----------------------------------|-------------| | Host | PostgreSQL server address | 127.0.0.1 | | Port | PostgreSQL server port | 5432 | | Database | Database name | postgres | | SSL | Enable SSL connection | false | | User | Database user (credential) | — | | Password | Database password (credential) | — |

Node properties (async.pg)

| Field | Description | Default | |-----------------|---------------------------------------------------|---------| | Name | Optional display name for the node | — | | Server | Reference to a postgresDB config node | — | | Max Concurrency | Maximum number of queries running simultaneously | 1 | | Query | SQL query template (Nunjucks syntax) | — |


5. Usage

  1. Add a postgresDB config node with your connection details.
  2. Drop an async.pg node onto your flow.
  3. Connect it to a postgresDB config node.
  4. Write your SQL query in the editor (Nunjucks templating supported).
  5. Connect an input and an output node.

On each incoming message, the node renders the SQL template against msg, executes the query, and sets msg.payload to the result rows before forwarding the message.


6. Templating (Nunjucks)

The SQL query is rendered using Nunjucks with the entire msg object as the template context.

SELECT * FROM orders WHERE id = {{ payload.id }};

INSERT INTO events (name, ts)
VALUES ('{{ topic }}', NOW());

Any property on msg is accessible directly by name.


7. Concurrency Model

Max Concurrency is the single source of truth for concurrency in this node.

  • It defines how many queries run in parallel.
  • The internal PostgreSQL connection pool is sized to the same value (pool.max = maxConcurrency).
  • Excess messages are held in an internal FIFO queue and dispatched as slots become free.

This guarantees:

| maxConcurrency | Behaviour | |------------------|---------------------------------------------------| | 1 | Strictly sequential — one query at a time | | N | Exactly N queries in parallel, no hidden buffering|

There is no independent pool configuration. The pool is an implementation detail.


8. Message Flow

msg arrives
    │
    ▼
enqueued (FIFO)
    │
    ▼ (slot available)
SQL rendered via Nunjucks
    │
    ▼
query executed
    │
    ▼
msg.payload = result.rows
    │
    ▼
msg forwarded

9. Status Indicator

The node status always follows the format:

<queued> (<running>/<maxConcurrency>)

| Example | Meaning | |-----------|----------------------------------------| | 0 (0/5) | Idle — no messages in queue or running | | 0 (3/5) | 3 queries running, none waiting | | 2 (5/5) | All 5 slots busy, 2 messages queued |


10. Error Handling

  • On query error, node.error(err, msg) is called with the original message.
  • The node remains active — the queue continues processing subsequent messages.
  • Pool-level errors are also reported via node.error.

11. Design Principles

  • Predictability over flexibility — one concurrency knob, no hidden limits.
  • No silent buffering — the queue is visible in the status indicator at all times.
  • Fail loudly — errors surface immediately via node.error, never swallowed.
  • Minimal footprint — no retries, no fallbacks, no extra abstractions.