Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including now-token with all npm packages installed. Try it out:

var nowToken = require("now-token")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

now-token v0.1.5

Get your authentication token generated by the Now CLI

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

OptionDescriptionDefault
providerGet the token for a provider other than Nowsh

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free