Cloud Tasks API client for Node.js
- Cloud Tasks Node.js Client API Reference
- Cloud Tasks Documentation
- github.com/googleapis/nodejs-tasks
Read more about the client libraries for Cloud APIs, including the older Google APIs Client Libraries, in Client Libraries Explained.
Table of contents:
- Select or create a Cloud Platform project.
- Enable billing for your project.
- Enable the Cloud Tasks API.
- Set up authentication with a service account so you can access the API from your local workstation.
npm install @google-cloud/tasks
// Imports the Google Cloud Tasks library.
const {CloudTasksClient} = require('@google-cloud/tasks');
// Instantiates a client.
const client = new CloudTasksClient();
// TODO(developer): Uncomment these lines and replace with your values.
// const project = 'my-project-id';
// const queue = 'my-appengine-queue';
// const location = 'us-central1';
// const payload = 'hello';
// Construct the fully qualified queue name.
const parent = client.queuePath(project, location, queue);
const task = {
appEngineHttpRequest: {
httpMethod: 'POST',
relativeUri: '/log_payload',
},
};
if (payload) {
task.appEngineHttpRequest.body = Buffer.from(payload).toString('base64');
}
if (inSeconds) {
task.scheduleTime = {
seconds: inSeconds + Date.now() / 1000,
};
}
const request = {
parent: parent,
task: task,
};
console.log('Sending task:');
console.log(task);
// Send create task request.
const [response] = await client.createTask(request);
const name = response.name;
console.log(`Created task ${name}`);
Samples are in the samples/
directory. The samples' README.md
has instructions for running the samples.
Sample | Source Code | Try it |
---|---|---|
Cloud Tasks Create HTTP Target | source code | |
Cloud Tasks Create HTTP Target with Token | source code | |
Create Queue | source code | |
Cloud Tasks Create App Engine Target | source code | |
Delete Queue | source code | |
List Queues | source code | |
Quickstart | source code | |
Server | source code |
The Cloud Tasks Node.js Client API Reference documentation also contains samples.
This library follows Semantic Versioning.
This library is considered to be General Availability (GA). This means it is stable; the code surface will not change in backwards-incompatible ways unless absolutely necessary (e.g. because of critical security issues) or with an extensive deprecation period. Issues and requests against GA libraries are addressed with the highest priority.
More Information: Google Cloud Platform Launch Stages
Contributions welcome! See the Contributing Guide.
Apache Version 2.0
See LICENSE