Skip to content
Node.js library for the Stripe API.
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Added a template for GitHub issues Nov 3, 2016
examples/webhook-signing Use ESLint instead of jscs Oct 16, 2017
lib Rework error handling around exec (#598) Apr 23, 2019
test Rework error handling around exec (#598) Apr 23, 2019
testUtils Override host per method instead of per resource Sep 19, 2018
.eslintrc.js Clarify autoPagingEach async usage Oct 18, 2018
.npmignore Add `.npmignore` to create a leaner package Jun 7, 2018
.npmrc Prevent package-lock.json files from being created Sep 7, 2017
.travis.yml Start testing Node 10 on Travis CI May 28, 2018 Bump version to 6.30.0 Apr 22, 2019
LICENSE rm focused spec and add stripe copyright Oct 8, 2013 Clarify that automatic network retries occur for most api errors (#567) Feb 14, 2019

Stripe Node.js Library

Version Build Status Coverage Status Downloads Try on RunKit

The Stripe Node library provides convenient access to the Stripe API from applications written in server-side JavaScript.

Please keep in mind that this package is for use with server-side Node that uses Stripe secret keys. To maintain PCI compliance, tokenization of credit card information should always be done with Stripe.js on the client side. This package should not be used for that purpose.


See the Node API docs.


Install the package with:

npm install stripe --save


The package needs to be configured with your account's secret key which is available in your Stripe Dashboard. Require it with the key's value:

const stripe = require('stripe')('sk_test_...');

const customer = await stripe.customers.create({
  email: ''

Or with versions of Node.js prior to v7.9:

var stripe = require('stripe')('sk_test_...');

  { email: '' },
  function(err, customer) {
    err; // null if no error occurred
    customer; // the created customer object

Or using ES modules, this looks more like:

import Stripe from 'stripe';
const stripe = Stripe('sk_test_...');

Usage with TypeScript

Stripe does not currently maintain typings for this package, but there are community typings available from DefinitelyTyped.

To install:

npm install --dev @types/stripe

To use:

// Note `* as` and `new Stripe` for TypeScript:
import * as Stripe from 'stripe';
const stripe = new Stripe('sk_test_...');

const customer: Promise<Stripe.customers.ICustomer> = stripe.customers.create(/* ... */);

Using Promises

Every method returns a chainable promise which can be used instead of a regular callback:

// Create a new customer and then a new charge for that customer:
  email: ''
}).then((customer) => {
  return stripe.customers.createSource(, {
    source: 'tok_visa'
}).then((source) => {
  return stripe.charges.create({
    amount: 1600,
    currency: 'usd',
    customer: source.customer
}).then((charge) => {
  // New charge created on a new customer
}).catch((err) => {
  // Deal with an error

Configuring Timeout

Request timeout is configurable (the default is Node's default of 120 seconds):

stripe.setTimeout(20000); // in ms (this is 20 seconds)

Configuring For Connect

A per-request Stripe-Account header for use with Stripe Connect can be added to any method:

// Retrieve the balance for a connected account:
  stripe_account: 'acct_foo'
}).then((balance) => {
  // The balance object for the connected account
}).catch((err) => {
  // Error

Configuring a Proxy

An https-proxy-agent can be configured with setHttpAgent.

To use stripe behind a proxy you can pass to sdk:

if (process.env.http_proxy) {
  const ProxyAgent = require('https-proxy-agent');
  stripe.setHttpAgent(new ProxyAgent(process.env.http_proxy));

Network retries

Automatic network retries can be enabled with setMaxNetworkRetries. This will retry requests n times with exponential backoff if they fail due to an intermittent network problem. Idempotency keys are added where appropriate to prevent duplication.

// Retry a request once before giving up

Examining Responses

Some information about the response which generated a resource is available with the lastResponse property:

charge.lastResponse.requestId // see:

request and response events

The Stripe object emits request and response events. You can use them like this:

const stripe = require('stripe')('sk_test_...');

const onRequest = (request) => {
  // Do something.

// Add the event handler function:
stripe.on('request', onRequest);

// Remove the event handler function:'request', onRequest);

request object

  api_version: 'latest',
  account: 'acct_TEST',       // Only present if provided
  idempotency_key: 'abc123',  // Only present if provided
  method: 'POST',
  path: '/v1/charges'

response object

  api_version: 'latest',
  account: 'acct_TEST',       // Only present if provided
  idempotency_key: 'abc123',  // Only present if provided
  method: 'POST',
  path: '/v1/charges',
  status: 402,
  request_id: 'req_Ghc9r26ts73DRf',
  elapsed: 445                // Elapsed time in milliseconds

Webhook signing

Stripe can optionally sign the webhook events it sends to your endpoint, allowing you to validate that they were not sent by a third-party. You can read more about it here.

Please note that you must pass the raw request body, exactly as received from Stripe, to the constructEvent() function; this will not work with a parsed (i.e., JSON) request body.

You can find an example of how to use this with Express in the examples/webhook-signing folder, but here's what it looks like:

const event = stripe.webhooks.constructEvent(

Writing a Plugin

If you're writing a plugin that uses the library, we'd appreciate it if you identified using stripe.setAppInfo():

  name: 'MyAwesomePlugin',
  version: '1.2.34', // Optional
  url: '', // Optional

This information is passed along when the library makes calls to the Stripe API.


As of stripe-node 6.11.0, you may auto-paginate list methods. We provide a few different APIs for this to aid with a variety of node versions and styles.

Async iterators (for-await-of)

If you are in a Node environment that has support for async iteration, such as Node 10+ or babel, the following will auto-paginate:

for await (const customer of stripe.customers.list()) {
  if (shouldStop()) {


If you are in a Node environment that has support for await, such as Node 7.9 and greater, you may pass an async function to .autoPagingEach:

await stripe.customers.list().autoPagingEach(async (customer) => {
  await doSomething(customer);
  if (shouldBreak()) {
    return false;
console.log('Done iterating.');

Equivalently, without await, you may return a Promise, which can resolve to false to break:

stripe.customers.list().autoPagingEach((customer) => {
  return doSomething(customer).then(() => {
    if (shouldBreak()) {
      return false;
}).then(() => {
  console.log('Done iterating.');

If you prefer callbacks to promises, you may also use a next callback and a second onDone callback:

  function onItem(customer, next) {
    doSomething(customer, function(err, result) {
      if (shouldStop(result)) {
        next(false); // Passing `false` breaks out of the loop.
      } else {
  function onDone(err) {
    if (err) {
    } else {
      console.log('Done iterating.');

If your onItem function does not accept a next callback parameter or return a Promise, the return value is used to decide whether to continue (false breaks, anything else continues).


This is a convenience for cases where you expect the number of items to be relatively small; accordingly, you must pass a limit option to prevent runaway list growth from consuming too much memory.

Returns a promise of an array of all items across pages for a list request.

const allNewCustomers = await stripe.customers.list({created: {gt: lastMonth}})
  .autoPagingToArray({limit: 10000});

More Information


Run all tests:

$ npm install
$ npm test

Run a single test suite:

$ npm run mocha -- test/Error.spec.js

Run a single test (case sensitive):

$ npm run mocha -- test/Error.spec.js --grep 'Populates with type'

If you wish, you may run tests using your Stripe Test API key by setting the environment variable STRIPE_TEST_API_KEY before running the tests:

$ export STRIPE_TEST_API_KEY='sk_test....'
$ npm test
You can’t perform that action at this time.