now-token

Get your authentication token generated by the Now CLI

Usage no npm install needed!

<script type="module">
  import nowToken from 'https://cdn.skypack.dev/now-token';
</script>

README

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