@vercel/client
v18.4.1
Published
[Join the Vercel Community](https://community.vercel.com/)
Keywords
Readme
@vercel/client
The official Node.js client for deploying to Vercel.
Usage
Firstly, install the package:
npm install @vercel/clientNext, load it:
const { createDeployment } = require('@vercel/client');Then call inside a for...of loop to follow the progress with the following arguments:
<path>- a directory path / file path / array of file paths (must be on the same level)<options>- An object containingtoken, an optionalteamIdand anyvercel.json-valid fields
async function deploy() {
let deployment;
for await (const event of createDeployment({
token: process.env.TOKEN,
path: '/Users/me/Code/myproject',
})) {
if (event.type === 'ready') {
deployment = event.payload;
break;
}
}
return deployment;
}The optional second argument accepts deployment options, either as an object or
as a Promise<DeploymentOptions>. Use a promise to resolve metadata concurrently
with local file collection:
const options = readDeploymentMetadata().then(gitMetadata => ({ gitMetadata }));
for await (const event of createDeployment(
{ token: process.env.TOKEN, path: '/path/to/project' },
options
)) {
// Handle deployment progress.
}Start consuming the iterator immediately after creating the promise: the async
generator begins running on its first iteration. File collection and the
hashes-calculated event can finish before the options resolve, but uploads and
deployment creation wait for them. If the options reject, iteration throws before
uploading or creating the deployment. If local file collection fails first, that
error is reported and a later options rejection is handled internally.
Full list of events:
[
// File events
'hashes-calculated',
'file-count',
'file-uploaded',
'all-files-uploaded',
// Deployment events
'created',
'building',
'ready',
'alias-assigned',
'warning',
'error',
];You can also get the events set programmatically:
import { EVENTS } from '@vercel/client';