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

@topcs/node-red-contrib-postgres

v2.0.1

Published

Yet another Node-RED node to query PostgreSQL with query parameters and listening

Readme

🐘 @topcs/node-red-contrib-postgres

Three nodes for PostgreSQL in Node-RED. Config node manages the connection pool. Query node executes SQL with Mustache templates and parameterized queries. Listener node pushes real-time NOTIFY events into your flow with automatic reconnection.

✨ Features

This fork brings a full TypeScript rewrite with 137 tests and zero regressions:

| Feature | Description | |---------|-------------| | 🔒 Parameterized queries | msg.params$1, $2, ... | | 🎨 Named parameters | {name: 'value'} → auto-bound in insertion order | | 🧩 Mustache templates | SELECT * FROM {{msg.table}} | | 🔄 Multi-step transactions | Array of {query, params, output}BEGIN / COMMIT / ROLLBACK | | 📡 Real-time LISTEN/NOTIFY | Push events from Postgres, auto-reconnects on connection drop | | 🔮 Cursor streaming | DECLARE / FETCH large result sets in configurable batches | | 📦 COPY import/export | High-speed CSV via PostgreSQL COPY protocol | | ♻️ Self-healing retry | Retries on deadlock (40P01), serialization failures, connection drops with jittered backoff | | 💚 Pool health badge | Active / idle / waiting / total visible on the node | | 🔐 Full SSL | sslmode, CA cert, client cert/key — RDS/Azure/Supabase ready | | 🧹 Structured errors | msg.error.code, .detail, .constraint, .table | | ⏱️ Query timeout | Per-node SET statement_timeout with guaranteed reset | | 🎯 Type mapping | NUMERIC→number, TIMESTAMPTZ→ISO, JSONB→object | | ⚡ Prepared statements | Auto-named via MD5 hash, no configuration needed | | 🛡️ Channel sanitization | LISTEN/UNLISTEN uses pg-format %I | | 🧪 137 tests | Zero regressions |

📦 Install

npm install @topcs/node-red-contrib-postgres

Or use Node-RED's Manage Palette → search @topcs/node-red-contrib-postgres.

🚀 Quick Start

1. Drop a PostgresDBNode — set host, port, database, user, password. Configure SSL if needed. The badge shows pool health.

2. Wire a PostgresNode — write SQL with optional {{msg.field}} templates.

Parameterized:

{"params": [42, "hello"]}

Named parameters:

{"params": {"id": 42, "name": "Alice"}}

Enable "Named Parameters" toggle on the node.

Transaction (array of queries on one connection):

{"payload": [
  {"query": "INSERT INTO users VALUES($1, $2)", "params": {"id": 1, "name": "Ada"}, "output": true},
  {"query": "INSERT INTO logs VALUES($1)", "params": {"action": "created"}}
]}

Enable "Transaction Mode". First output: true entry determines msg.payload.rows.

Cursor streaming: Enable "Cursor Mode". SELECT queries stream batches via DECLARE / FETCH:

// Sequential messages per batch:
{"payload": [...rows], "batch": {"index": 0, "rows": 100, "total": 100}}
// Final signal:
{"payload": [], "complete": true, "total": 10500}

3. Add a PostgresListenerNode — set channel name. When Postgres sends NOTIFY channel, 'payload', it arrives as {channel, payload, _original}. JSON payloads auto-parse. Connection drops auto-recover.

🔧 Editor Toggles

| Toggle | Description | |--------|-------------| | Throw Exception | Halt the flow on SQL error (throwErrors) | | Named Parameters | Bind msg.params object as $1, $2, ... | | Transaction Mode | Execute msg.payload array atomically | | Cursor Mode | Stream SELECT results in batches | | COPY Mode | Use COPY protocol for CSV import/export | | Retry on Transient Errors | Auto-retry deadlocks, serialization failures, connection drops | | Type Mapping | NUMERIC→number, TIMESTAMPTZ→ISO, JSONB→object |

🎯 Requirements

  • Node.js >= 18.0.0
  • Node-RED >= 3.0.0
  • PostgreSQL (any recent version)

🧪 Development

npm install
npm run build    # tsc + build HTML templates
npm test         # 137 tests (Jest)
npm run lint     # ESLint 9.x

📜 License

GNU AGPL-3.0. Originally by doing-things-with-node-red, forked and maintained by Andrea Batazzi. Revived with TypeScript.


NPM