Skip to content
This repository has been archived by the owner on Feb 5, 2022. It is now read-only.
/ now-token Public archive

Get your Now authentication token from Node or the command line

License

Notifications You must be signed in to change notification settings

shawnbot/now-token

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Get your Now authentication token from Node or the command line

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published