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

dnsimple

v7.4.0

Published

A Node.JS client for the DNSimple API.

Downloads

4,350

Readme

DNSimple Node.js Client

A Node.js client for the DNSimple API v2 with TypeScript definitions.

Build Status js-semistandard-style npm version npm downloads

Requirements

The dnsimple-node package requires Node.js 14.0.0 or higher.

You must also have an activated DNSimple account to access the DNSimple API.

Installation

You can install this package directly from the GitHub repo with npm install dnsimple/dnsimple-node.

Alternatively, install the latest stable version from NPM with npm install dnsimple.

Usage

This library is a Node.js client you can use to interact with the DNSimple API v2. TypeScript definitions are provided for all API method parameters and responses.

Note that in all examples below, the accessToken must be an OAuth token as described in the DNSimple API Access Token documentation.

All client methods that call out to the DNSimple API are async and will return a Promise. The examples below demonstrate basic usage.

const { DNSimple } = require("dnsimple");
// Or use this if you're using TypeScript:
// import { DNSimple } from "dnsimple";

const client = new DNSimple({
  accessToken: process.env.TOKEN,
});

// Fetch your details
const response = await client.identity.whoami();
// All responses have a `data` property if there's response data.
const accountId = response.data.account.id;

// List your domains
const { data: domains1 } = await client.domains.listDomains(accountId);
const { data: domains3 } = await client.domains.listDomains(accountId, { page: 3 });

// Create a domain
const { data: createdDomain } = await client.domains.createDomain(accountId, { name: "example.com" });

// Get a domain
const { data: domain } = await client.domains.getDomain(accountId, "example.com");

To be run like this:

TOKEN=[TOKEN VALUE GOES HERE] node test.js

Take a look at https://github.com/dnsimple/hello-domains-node for an example app that authorizes via OAuth and displays your domain list.

Pagination

There are helper submethods available on API methods that are paginated to assist with fetching items across all pages.

For an API that returns a paginate property, you can use either the iterateAll or collectAll submethods:

  • iterateAll: return an asynchronous iterator of items that are returned from the API. When the last item on a page is iterated, the next page will be fetched. This continues until there are no more pages.

  • collectAll: fetch all pages and collect all the items in order into an array.

Examples:

// iterateAll
for await (const certificate of client.certificates.listCertificates.iterateAll(1010, "bingo.pizza")) {
  console.log(certificate);
}
// collectAll
const certificates: Array<Certificate> = await client.certificates.listCertificates.collectAll(1010, "bingo.pizza");
console.log(certificates.length);

Sandbox Environment

We highly recommend testing against our sandbox environment before using our production environment. This will allow you to avoid real purchases, live charges on your credit card, and reduce the chance of your running up against rate limits.

The client supports both the production and sandbox environment. To switch to sandbox pass the sandbox API host using the baseUrl property when you construct the client:

const { DNSimple } = require("dnsimple");
const client = new DNSimple({
  baseUrl: "https://api.sandbox.dnsimple.com",
  accessToken: process.env.TOKEN,
});

You will need to ensure that you are using an access token created in the sandbox environment. Production tokens will not work in the sandbox environment.

Setting a custom User-Agent header

You customize the User-Agent header for the calls made to the DNSimple API:

const { DNSimple } = require("dnsimple");
const client = new DNSimple({
  userAgent: "my-app",
  accessToken: process.env.TOKEN,
});

The value you provide will be appended to the default User-Agent the client uses. For example, if you use my-app, the final header value will be dnsimple-node/x.x.x my-app (note that it will vary depending on the client version).

License

Copyright © 2016–2023 DNSimple Corporation. This is Free Software distributed under the MIT license.