
Security News
Static vs. Runtime Reachability: Insights from Latio’s On the Record Podcast
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
PostgresSQL client to Nodejs servers
Did you like the project? Please, considerate a donation to help improve!
PostgresSQL client to Nodejs servers✨
Connect your database easily using the pgnode package
To install the module in your project just run the command below:
npm i pgnode
or
yarn add pgnode
Now in your project just import the module like this:
const pg = require("pgnode");
Or you can use import:
import pg from "pgnode";
This is the simplest possible way to connect, query, and disconnect with async/await:
import pg, { Client, Pool } from "pgnode";
const config = {
user: process.env.POSTGRES_USER,
host: process.env.POSTGRES_HOST,
database: process.env.POSTGRES_DATABASE,
password: process.env.POSTGRES_PASSWORD,
port: Number(process.env.POSTGRES_PORT),
};
const client = new pg.Client({ ...config });
function query(sql, params) {
return client
.connect()
.then(() => client.query(sql, params))
.then((res) => {
client.end();
return res;
});
}
import {tx, Client, Pool} from 'pgnode';
const client = new Client({
user: process.env.POSTGRES_USER,
host: process.env.POSTGRES_HOST,
database: process.env.POSTGRES_DATABASE,
password: process.env.POSTGRES_PASSWORD,
port: Number(process.env.POSTGRES_PORT)
});
const pool = new Pool({...client});
export async function createTable(){
return await tx(pool, async (db) => {
await db.query(`
CREATE TABLE IF NOT EXISTS test
(
id SERIAL PRIMARY KEY,
name TEXT NOT NULL
);`);
});
}
// or use a generator function to create the transactions
export function* createTableGenerator(){
yield tx(pool, async (db) => {
await db.query(`
CREATE TABLE IF NOT EXISTS test
(
id SERIAL PRIMARY KEY,
name TEXT NOT NULL
);`);
});
// create another transaction
yield tx(pool, async (db) => {
await db.query(`
INSERT INTO test (name) VALUES ('test');`);
});
}
tls.connect
options being passed to the client/pool constructor under the ssl
option.LISTEN/NOTIFY
COPY TO/COPY FROM
pg.Client
and pg.Pool
are ES6 classespg.Client.prototype.query
and pg.Pool.prototype.query
^v16x
FAQs
PostgresSQL client to Nodejs servers
The npm package pgnode receives a total of 4 weekly downloads. As such, pgnode popularity was classified as not popular.
We found that pgnode demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.