
Product
Socket for Jira Is Now Available
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.
node-red-contrib-postgres-variable
Advanced tools
PostgreSQL module for Node-RED with dynamic configuration from contexts (flow, global, environment)
A Node-RED module for PostgreSQL database operations with support for dynamic configuration from different contexts (flow, global, environment variables).
Edited by Andrii Lototskyi
npm install node-red-contrib-postgres-variable
The PostgreSQL database configuration node supports the following parameters, each can be sourced from different contexts:
| Parameter | Description | Context Types | Default |
|---|---|---|---|
| Host | PostgreSQL server hostname | str, flow, global, env | localhost |
| Port | PostgreSQL server port | str, flow, global, env | 5432 |
| Database | Database name | str, flow, global, env | - |
| Username | Database username | str, flow, global, env | - |
| Password | Database password | str, flow, global, env | - |
🔐 Password Security Note: When password type is set to "str" (string), the password is securely stored in Node-RED's credentials system and displayed as a password field (hidden). For other types (flow, global, env), the password reference is stored in the flow configuration for portability.
| Parameter | Description | Context Types | Default |
|---|---|---|---|
| SSL | Enable SSL connection | bool, flow, global, env | false |
| Ignore SSL Certificate | Skip certificate validation | bool, flow, global, env | false |
| SSL Certificate Path | Path to SSL certificate file | str, flow, global, env | - |
flow.get(key))global.get(key))process.env[key])Configure Database Node:
localhost (string)5432 (string)mydb (string)postgres (string)secret (string)Use in Flow:
msg.payload = "SELECT * FROM users WHERE id = $userId";
msg.queryParameters = { userId: 123 };
return msg;
// Set in a function node before the postgres node
flow.set("db_host", "production-server");
flow.set("db_name", "prod_database");
Configure database node:
db_host (flow context)db_name (flow context)// Set in a function node
global.set("postgres_port", "5433");
global.set("postgres_user", "admin");
Configure database node:
postgres_port (global context)postgres_user (global context)Set environment variables:
export DB_HOST=production-server
export DB_PORT=5432
export DB_NAME=production_db
export DB_USER=prod_user
export DB_PASSWORD=secure_password
Configure database node:
DB_HOST (environment)DB_PORT (environment)DB_NAME (environment)DB_USER (environment)DB_PASSWORD (environment)// Environment variables
export SSL_ENABLED=true
export SSL_CERT_PATH=/path/to/certificate.pem
Configure database node:
SSL_ENABLED (environment) → truefalse (boolean)SSL_CERT_PATH (environment) → /path/to/certificate.pemConfigure database node:
true (boolean)true (boolean)// In a function node
flow.set("use_ssl", true);
flow.set("ignore_cert", false);
flow.set("cert_path", "/secure/path/cert.pem");
Configure database node:
use_ssl (flow context)ignore_cert (flow context)cert_path (flow context)msg.payload = "SELECT * FROM users";
return msg;
msg.payload = "SELECT * FROM users WHERE age > $minAge AND city = $userCity";
msg.queryParameters = {
minAge: 18,
userCity: "New York"
};
return msg;
msg.payload = "INSERT INTO users (name, email, age) VALUES ($name, $email, $age)";
msg.queryParameters = {
name: "John Doe",
email: "john@example.com",
age: 30
};
return msg;
msg.payload = "SELECT * FROM " + msg.tableName + " WHERE id = $recordId";
msg.queryParameters = {
recordId: msg.payload.id
};
return msg;
You can also define custom connection configurations in Node-RED settings.js:
module.exports = {
// ... other settings
pgConnects: {
"production": {
user: "prod_user",
password: "prod_password",
host: "prod-server",
port: 5432,
database: "production_db",
ssl: true,
ignore_check_ssl: false,
ssl_path: "/path/to/prod-cert.pem"
},
"development": {
user: "dev_user",
password: "dev_password",
host: "localhost",
port: 5432,
database: "dev_db",
ssl: false
}
}
};
Use custom connection:
msg.connectName = "production"; // or "development"
msg.payload = "SELECT * FROM users";
return msg;
The module implements intelligent password handling based on the selected type:
When password type is set to "str":
When password type is set to "flow", "global", or "env":
// Configuration: Password type = "str", value = "mySecretPassword"
// Result: Password stored securely in credentials, not in flow
// Configuration: Password type = "env", value = "DB_PASSWORD"
// Environment: DB_PASSWORD=dev_password_123
// Result: Password resolved from environment at runtime
// In a function node:
global.set("current_db_password", "dynamic_password_" + Date.now());
// Configuration: Password type = "global", value = "current_db_password"
// Result: Password resolved from global context at runtime
The module provides comprehensive error handling:
// Errors are sent to the node's error output
// and also attached to the message
if (msg.payload.error) {
node.warn("Database error: " + msg.payload.error);
return null; // Stop processing
}
The SSL configuration follows this logic:
If you're upgrading from a previous version that used Node-RED credentials:
pg: PostgreSQL client for Node.jsnode-postgres-named: Named parameter support for node-postgresApache License 2.0
Contributions are welcome! Please feel free to submit a Pull Request.
For issues and questions, please use the GitHub issue tracker.
FAQs
PostgreSQL module for Node-RED with dynamic configuration from contexts (flow, global, environment)
We found that node-red-contrib-postgres-variable demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.