now-api v0.3.0
𝚫 now API 
Node.js module to interact with the official 𝚫 now API.
You need to provide your API token, which you can obtain here.
It is possible to pass it as a parameter or with the NOW_TOKEN
environment variable.
When no token is given, it will use the one contained in your .now.json
file.
npm install --save now-api
Example
var Now = require('now-api');
var now = Now('YOUR TOKEN');
// Supports Promises
now.getDeployments().then((deployments) => {
console.log(deployments);
}).catch((err) => {
console.error(err);
});
// Or go old-school with callbacks
now.getDeployments(function(err, deployments) {
if (err) throw err;
console.log(deployments);
});
API Reference
Kind: global class
- Now
- new Now([token])
- .getDeployments([callback]) ⇒ Promise
- .getDeployment(id, [callback]) ⇒ Promise
- .createDeployment(body, [callback]) ⇒ Promise
- .deleteDeployment(id, [callback]) ⇒ Promise
- .getFiles(id, [callback]) ⇒ Promise
- .getFile(id, fileId, [callback]) ⇒ Promise
- .getAliases([id OR callback], [callback]) ⇒ Promise
- .createAlias(id, alias, [callback]) ⇒ Promise
- .deleteAlias(id, [callback]) ⇒ Promise
new Now(token)
Initializes the API. Looks for token in ~/.now.json if none is provided.
Param | Type | Description |
---|---|---|
token | String | Your now API token. |
now.getDeployments(callback) ⇒ Promise
Returns an array with all deployments.
Kind: instance method of Now
See: https://zeit.co/api#list-endpoint
Param | Type | Description |
---|---|---|
callback | function | Callback will be called with (err, deployments) |
now.getDeployment(id, callback) ⇒ Promise
Returns an object with deployment data.
Kind: instance method of Now
See: https://zeit.co/api#get-endpoint
Param | Type | Description |
---|---|---|
id | String | ID of deployment |
callback | function | Callback will be called with (err, deployment) |
now.createDeployment(body, callback) ⇒ Promise
Creates a new deployment and returns its data.
Kind: instance method of Now
See: https://zeit.co/api#instant-endpoint
Param | Type | Description |
---|---|---|
body | Object | Object a package key (for package.json data). The other keys should represent a file path, with their respective values containing the file contents. |
callback | function | Callback will be called with (err, deployment) |
now.deleteDeployment(id, callback) ⇒ Promise
Deletes a deployment and returns its data.
Kind: instance method of Now
See: https://zeit.co/api#rm-endpoint
Param | Type | Description |
---|---|---|
id | String | ID of deployment |
callback | function | Callback will be called with (err, deployment) |
now.getFiles(id, callback) ⇒ Promise
Returns an array with the file structure.
Kind: instance method of Now
See: https://zeit.co/api#file-structure-endpoint
Param | Type | Description |
---|---|---|
id | String | ID of deployment |
callback | function | Callback will be called with (err, fileStructure) |
now.getFile(id, fileId, callback) ⇒ Promise
Returns the content of a file.
Kind: instance method of Now
See: https://zeit.co/api#file--endpoint
Param | Type | Description |
---|---|---|
id | String | ID of deployment |
fileId | String | ID of the file |
callback | function | Callback will be called with (err, file) |
now.getAliases(id OR callback, callback) ⇒ Promise
Returns an array with all aliases.
Kind: instance method of Now
See: https://zeit.co/api#user-aliases
Param | Type | Description |
---|---|---|
id OR callback | String | function | ID of deployment or callback |
callback | function | Callback will be called with (err, aliases) |
now.createAlias(id, alias, callback) ⇒ Promise
Creates an alias for the given deployment.
Kind: instance method of Now
See: https://zeit.co/api#create-alias
Param | Type | Description |
---|---|---|
id | String | ID of deployment |
alias | String | Hostname or custom url for the alias |
callback | function | Callback will be called with (err, data) |
now.deleteAlias(id, callback) ⇒ Promise
Deletes an alias and returns a status.
Kind: instance method of Now
See: https://zeit.co/api#delete-user-aliases
Param | Type | Description |
---|---|---|
id | String | ID of alias |
callback | function | Callback will be called with (err, status) |