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

node-pgparser

v16.1.14

Published

Node.js module for parsing PostgreSQL queries

Readme

node-pgparser

node-pgparser - Node.js wrapper for libpg_query C library.

It parses the query and returns the parse tree or error object.

Installation

If you use a corporate certificate to internet access please add it to node first:

# linux and macos
export NODE_EXTRA_CA_CERTS=/path/to/cert

# windows
set NODE_EXTRA_CA_CERTS=/path/to/cert

then run the command

npm install node-pgparser

Uses node-pre-gyp to download prebuild binaries from S3 Amazon.

Currently supports Nodejs v16,v18,v20,v22,v24 for Linux, Macos (x64 and arm64) and Windows.

Example

Parse SQL query

const pgparser = require('node-pgparser');

let tree = pgparser('select 1');
if (tree instanceof Error) {
  console.log('Error parsing: ', tree);
} else {
  console.dir(tree, {depth: null});
}

Result

{
  version: 160001,
    stmts: [
    {
      stmt: {
        SelectStmt: {
          targetList: [
            {
              ResTarget: {
                val: { A_Const: { ival: { ival: 1 }, location: 7 } },
                location: 7
              }
            }
          ],
          limitOption: 'LIMIT_OPTION_DEFAULT',
          op: 'SETOP_NONE'
        }
      }
    }
  ]
}

Parse PL/pgSQL

const pgparser = require('node-pgparser');

let tree = pgparser('DO $$ BEGIN SELECT 1; END$$;', true);
if (tree instanceof Error) {
  console.log('Error parsing PL/pgSQL: ', tree);
} else {
  console.dir(tree, {depth: null});
}

Result

[
  {
    PLpgSQL_function: {
      datums: [
        {
          PLpgSQL_var: {
            refname: 'found',
            datatype: { PLpgSQL_type: { typname: 'UNKNOWN' } }
          }
        }
      ],
      action: {
        PLpgSQL_stmt_block: {
          lineno: 1,
          body: [
            {
              PLpgSQL_stmt_execsql: {
                lineno: 1,
                sqlstmt: { PLpgSQL_expr: { query: 'SELECT 1', parseMode: 0 } }
              }
            },
            { PLpgSQL_stmt_return: {} }
          ]
        }
      }
    }
  }
]

Versions

| PG Major Version | libpg_query | Branch | npm |--------------------------|-------------|--------------------------------------------------------------|---------| | 16 | 16-latest | pg16 | node-pgparser@16 | 15 | 15-latest | pg15 | node-pgparser@15 | 14 | 14-latest | pg14 | node-pgparser@14 | 13 | 13-latest | pg13 | node-pgparser@13