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

lob

v6.6.3

Published

Lob API wrapper

Downloads

56,154

Readme

lob-node

NPM version Downloads Build Status Dependency Status Dev Dependency Status Coverage Status

Node.js wrapper for the Lob.com API. See full Lob.com documentation here.


Starting a new project, we recommend using our TypeScript SDK!

Move your existing project from lob-node to lob-typescript-sdk? Checkout this migration guide.


Table of Contents

Getting Started

Here's a general overview of the Lob services available, click through to read more.

Please read through the official API Documentation to get a complete sense of what to expect from each endpoint.

Registration

First, you will need to first create an account at Lob.com and obtain your Test and Live API Keys.

Once you have created an account, you can access your API Keys from the Settings Panel.

Installation

lob-node can be installed through the npm:

$ npm install lob

To build and install from the latest source:

$ git clone [email protected]:lob/lob-node.git
$ npm install

Usage

const Lob = require('lob')('YOUR API KEY');

// change api version
const Lob = require('lob')('YOUR API KEY', { apiVersion: 'API-VERSION' });

// change internal defaults (e.g. host)
const options = {/* see options below */};
const Lob = require('lob')('YOUR API KEY', options);

// you can also just pass options
const options = { apiKey: 'foo', host: 'bar' };
const Lob = require('lob')(options);

// callback pattern
Lob.addresses.list((err, body) => {
  if (err) return callback(err);
  return callback(null, body.data);
});

Additionally, every resource method returns a promise, so you don't have to use the regular callback. E.g.

const Lob = require('lob')('YOUR API KEY');

Lob.addresses.list()
.then((res) => {
  console.log(res.data);
})
.catch((e) => {
  console.log(e);
});

Options

The Lob constructor accepts an options object which may contain one or more of the following options:

  • apiVersion - Optionally set the version of the Lob API to use. Defaults to latest.
  • host - Override the default host API calls are issued to.
  • userAgent - Override the default userAgent.
  • headers - Edit the headers sent in all API calls.
  • agent - Override the default HTTP agent used to make requests.

Examples

We've provided various examples for you to try out here.

There are simple scripts to demonstrate how to create all the core Lob objects (checks, letters, postcards. etc.) as well as more complex examples that utilize other libraries and external files.

Accessing Response Headers

You can access response headers via a hidden _response property.

Lob.addresses.list()
.then((res) => {
  res._response.headers['content-type'];
  // => "application/json; charset=utf-8"
});

You can also access headers from errors.

Lob.addresses.retrieve('adr_bad_id')
.catch((err) => {
  err._response.headers['content-type'];
  // => "application/json; charset=utf-8"
});

API Documentation

The full and comprehensive documentation of Lob's APIs is available here.

Contributing

To contribute, please see the CONTRIBUTING.md file.

Testing

To run the tests with coverage:

LOB_API_KEY=YOUR_TEST_API_KEY npm test

To run the tests without coverage:

LOB_API_KEY=YOUR_TEST_API_KEY npm run test-no-cover

=======================

Copyright © 2013 Lob.com

Released under the MIT License, which can be found in the repository in LICENSE.txt.