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

rnv-data-client

v1.0.3

Published

A simple node.js client for the RNV Data Hub API

Downloads

26

Readme

RNV Open Data Client

NPM

A simple client in node.js to access the RNV Open Data API.

Install client from npm

$ npm install rnv-data-client

Usage example

The usage example contains two ways of using the RNV Open Data Client.

  1. Dynamically obtains an access token, when needed
  2. Always obtains an access token

For obtaining credentials for RNV Open Data API in environment variables, see the section 'preparation-steps' below.

const dotenv = require('dotenv');
const client = require('rnv-data-client').client;
const exampleQueries = require('rnv-data-client').examples;

dotenv.config();

// Run prepare_env_file.sh to create an env file 
CLIENT_API_URL = process.env.CLIENT_API_URL;
OAUTH_URL = process.env.OAUTH_URL;
CLIENT_ID = process.env.CLIENT_ID;
CLIENT_SECRET = process.env.CLIENT_SECRET;
RESOURCE_ID = process.env.RESOURCE_ID;
// Modify this path when you copy this solution 
ACCESS_TOKEN_CACHE_PATH = "./at_cache.json";

// Checking that the .env file was loaded
console.log("CLIENT API URL: " + CLIENT_API_URL); 

// Simulate an async context 
(async () => {
    try {
        let DYN = true; 
        if (DYN){
            // Dynamically obtain an access token (only if token not cached and cache not expired)
            const at = await client.obtainAccessToken();
            // Change the key to use other queries here
            query = exampleQueries["stations"]
            console.log("Doing a query: " + query)
            const qres = await client.doQuery(query, at);
            console.log("Response to query: " + JSON.stringify(qres).substring(0, 200))

        }else{
            // Directly obtain access token 
            const at_info = await client.requestAccessToken();
            query = exampleQueries["stations"]
            console.log("Doing a query: " + query)
            const qres = await client.doQuery(query, at_info.access_token);
            console.log("Response to query: " + JSON.stringify(qres).substring(0, 200))
        }
    } catch (error) {
        console.error("Error while running the app: " + error)
    }
})();

Debug

$ DEBUG=dataclient node \<your main\>.js 

Or set the DEBUG variable in your runtime environment.

Run Tests

$ npm run test

Preparation steps

Obtain Credentials

To get access to our Open Data Hub API with your solutions, it is necessary to have an oauth2 access token. You need to go through several steps to generate such a token

  1. You register with your name and email for "Graphql" access with the reason "Upper Hackathon 24" here. Open RNV Formular
  2. In around 10 minutes you should receive a mail with your basic credentials, it's recommended to save the mail
  3. From these credentials you can generate an access token for your coded clients, there are several ways to obtain such a token, some of them are described here.

Prepare credentials

The client for node.js is in this repo in the node/ folder.

  1. Download the graphql.http file to this repo and place it in the root path.
  2. Download the preparation script from gist (see below)
  3. Run the shell script ./prepare_env_file.sh this will generate a .env file which is read by the node.js application

On Unix/Mac/Linux

You can copy the shell-script from node_modules if using npm.

$ curl https://gist.github.com/rnv-opendata/8365b1317505a80359491c2124a05e94 > prepare_env_file.sh
$ sudo chmod u+rwx prepare_env_file.sh 
$ ./prepare_env_file.sh > .envs

On Windows

$ curl https://gist.github.com/rnv-opendata/900d43affca063caed7918f91d9531b5 > prepare_env_file.cmd  
$ pwsh prepare_env_file.cmd

Important Links

  1. RNV Data-Hub-API Main Page and Credentials Request
  2. RNV Opendata GitHub Repository

References

  1. Badges for npm