now-token

0.1.5 • Public • Published

now-token

Get the Now authentication token generated by the Now CLI in Node or from the command line.

This should make it much easier to work with the Now API. Note that in order to use this, you will either have to:

  1. Install the Now CLI (npm i -g now-cli) and run now login; or
  2. Set the NOW_TOKEN environment variable

How it works

The Now CLI stores tokens in ~/.now/auth.json under the credentials array, which should only have one entry in it unless you've authenticated with other providers. (Now refers to their own authentication provider as sh.)

If the NOW_TOKEN environment variable is not empty, we just return that.

Node API

This module exports a single function that resolves to your Now authentication token:

const nowToken = require('now-token')
const fetch = require('isomorphic-unfetch')
 
nowToken()
  .then(token => {
    return fetch('https://api.zeit.co/v2/now/deployments', {
      headers: {
        Authorization: `Bearer ${token}`
      }
    })
    .then(res => res.json())
  )
  .then(deployments => {
    console.warn(`You've got ${deployments.length} deployments!`
  })

See below for available options.

Command line

When you npm install now-token, you'll get a now-token executable in your npm bin.

Any of the available options can be passed to the now-token executable by prefixing it with --, e.g. --provider aws.

Options

Option Description Default
provider Get the token for a provider other than Now sh

Readme

Keywords

Package Sidebar

Install

npm i now-token

Weekly Downloads

0

Version

0.1.5

License

Unlicense

Unpacked Size

4.43 kB

Total Files

5

Last publish

Collaborators

  • shawnbot