@google-cloud/pubsub

The default export of the @google-cloud/pubsub package is the PubSub class.

See PubSub and ClientConfig for client methods and configuration options.

Examples

Install the client library with npm:

npm install @google-cloud/pubsub

Import the client library

const {PubSub} = require('@google-cloud/pubsub');

Create a client that uses Application Default Credentials (ADC):

const pubsub = new PubSub();

Create a client with explicit credentials:

const pubsub = new PubSub({
  projectId: 'your-project-id',
  keyFilename: '/path/to/keyfile.json'
});

Full quickstart example:

// Imports the Google Cloud client library
const {PubSub} = require('@google-cloud/pubsub');

async function quickstart(
  projectId = 'your-project-id', // Your Google Cloud Platform project ID
  topicName = 'my-topic' // Name for the new topic to create
) {
  // Instantiates a client
  const pubsub = new PubSub({projectId});

  // Creates the new topic
  const [topic] = await pubsub.createTopic(topicName);
  console.log(`Topic ${topic.name} created.`);
}

Members

(static) v1 :object

Reference to internal generated clients, advanced use only.

Properties:
Name Type Description
PublisherClient constructor

Reference to v1.PublisherClient.

SubscriberClient constructor

Reference to v1.SubscriberClient.

See: