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 🙏

© 2024 – Pkg Stats / Ryan Hefner

vndb-api

v1.0.3

Published

An API wrapper for the vndb.org API

Downloads

46

Readme

codecov Build Status Documentation Status

VNDB API

This is a Node.js API for VNDB (the Visual Novel Database). VNDB provides it's own public API but it's not the best in terms of usability. This library provides an easily usable and intuitive Promise based interface to connect to and query the VNDB API.

The docs are available here.

HIGHLIGHTS

  • Allows configurable rate limiting.
  • Uses connection pooling.
  • Returns responses parsed into JSON

INSTALLATION

npm i vndb-api

USAGE

const VNDB = require('vndb-api')

// Create a client
const vndb = new VNDB('clientname', {
  // optionally, override any connection options you need to here, like
  minConnection: 1,
  maxConnection: 10,
})

// Send a query
vndb
  .query('dbstats')
  .then(response => {
    // Use the response
    console.log(response)
  })
  .catch(err => {
    // Handle errors
    console.log(err)
  })
  .finally(() => {
    // Destroy the client and any connections
    vndb.destroy()
  })

API

ConnectionOptions

You can optionally provide the connection options. Defaults are reasonably set according to https://vndb.org/d11, but you can override them if you want. The connection options are:

const vndb = new VNDB('clientname', {
  // The VNDB API hostname
  host: 'api.vndb.org',
  // The VNDB API port (use the TLS port)
  port: 19535,
  // You shouldn't need to change the host or the port unless VNDB changes them

  // The encoding to use
  encoding: 'utf-8',
  // The max number of queries allowed to send per queryInterval milliseconds
  queryLimit: 10,
  // The time limit in which at most queryLimit queries are allowed to send (in milliseconds)
  queryInterval: 30000,
  // The minimum number of connections to the API to keep in the pool
  minConnection: 1,
  // The maximum number of connections to the API allowed
  maxConnection: 10,
  // Unused/Free connections in the pool are destroyed after this many milliseconds
  idleTimeoutMillis: 30000,
  // If a connection is not established within this many milliseconds, an error with the corresponding reason is generated
  acquireTimeout: 30000,
  // If this is true, then the client errors out the first time unable to establish a connection and does not retry
  // If this is false, then the client will retry for acquireTimeout milliseconds to establish a connection
  propagateCreateError: false,
})

Methods

The following methods are available:

// The constructor
// Requires a parameter clientname which represents your client
// Optionally you can provide a ConnectionOptions object
const vndb = new VNDB('clientname', {
  // any connection options here
})
// query method
// Requires a VNDB API compatible qeury string
// Check out https://vndb.org/d11 for all types of queries
// Ex: 'dbstats' or 'get vn basic (id = 4)'
// Returns a Promise that resolves once the response is recieved or rejects on error
vndb
  .query('dbstats')
  .then(response => {
    // handle response
    // The format of responses varies according to the query
  })
  .catch(e => {
    // handle errors
  })
// destroy method
// Closes all connections and destroyes the client
// Returns a Promise that resolves once the client is destroyed
vndb.destroy().then(() => {
  // Client destroyed
})

Responses

The response of a query is a JSON object, but the fields can vary according to the query. The fields of any query are described here https://vndb.org/d11 Two fields are present on every response:

In case of a dbstats query:

status: 'dbstats'
searchType: 'dbstats'

In case of a get resource query (for example get vn ...) :

status: 'results'
searchType: 'resource' // 'vn' in example

Errors

The errors also vary according to the place they occur. But for all errors the error object has two fields:

status: 'error'
code: 'varies according to error'

... along with more fields desribing the errors.

Mainly there are two types of errors:

  • Those that occur while connecting, like CONTIMEOUT due to timeout or LOGINREJECT due to invalid client name, etc.

  • Those that happen due to a query. These erros are described here https://vndb.org/d11.