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

@ngrok/ngrok-api

v0.13.0

Published

<!-- Code generated for API Clients. DO NOT EDIT. -->

Downloads

815

Readme

Unstable

This library is currently unstable. We know of rough edges and are working to bring it to parity with our other API client libraries. Please feel free to try it out and let us know if you find it useful!

ngrok API client library for JavaScript and TypeScript

This library wraps the ngrok HTTP API to make it easier to consume in JavaScript or TypeScript.

Installation

The published library is available on npm.

npm install @ngrok/ngrok-api

Support

The best place to get support using this library is through the ngrok Slack Community. If you find any bugs, please contribute by opening a new GitHub issue.

Documentation

A quickstart guide and a full API reference are included in the ngrok TypeScript API documentation

Quickstart

After you've installed the package, you'll need an API Key. Create one on the API Keys page of your ngrok dashboard.

In your application's code, initialize an Ngrok client object with an API key. API resources can be accessed as properties of the Ngrok object.

import { Ngrok } from '@ngrok/ngrok-api';

const ngrok = new Ngrok({
  apiToken: '<API KEY>',
});

const domain = await ngrok.domains.create({
  name: 'your-name.ngrok.io',
});
console.log(domain);

Automatic Paging

The ngrok API pages all list resources but this library abstracts that implementation detail away from you. list() methods will return collections that can be iterated over and the implementation will fetch the pages from the API for you behind the scenes.

import { Ngrok } from '@ngrok/ngrok-api';

const ngrok = new Ngrok({
  apiToken: '<API KEY>',
});

(await ngrok.tunnels.list()).forEach(t => console.log(t));

Async Programming

All API methods return a Promise and are suitable for use in asynchronous programming. You can use callback chaining with .then() and .catch() syntax or the await keyword to wait for completion of an API call.

// await style
const cred = await ngrok.credentials.create({ description: 'example' });
console.log(cred);

// callback chaining
ngrok.credentials.create({ description: 'example' }).then(cred => {
  console.log(cred);
});

Error Handling

The ngrok API returns detailed information when an API call fails. If an error is encountered, API methods throw the rich Error type on resolution of a returned Promise. This allows your code to gracefully handle different error conditions.

The Error type includes a statusCode property which can be used to distinguish not found errors when a resource does not exist:

import { Error } from '@ngrok/ngrok-api';

try {
  await ngrok.ipPolicies.update({
    id: 'someInvalidId',
    description: 'updated description',
  });
} catch (err: Error) {
  if (err.statusCode == 404) {
    console.log('no ip policy with that id to update');
  }
}

Every error returned by the ngrok API includes a unique, documented error code that you can use to distinguish unique error conditions. Use the errorCode property in your application code to handle handle different error conditions.

import { Error } from '@ngrok/ngrok-api';

try {
  await ngrok.ipPolicies.create({
    action: 'something invalid',
  });
} catch (err: Error) {
  if (err.errorCode == 'ERR_NGROK_1410') {
    console.log('not a valid ip policy action');
  } else {
    console.log('some other error', err);
  }
}