Setting up the client

Now that we have provided the required credentials as well as subscribed to a Pub/Sub topic, we will set up the Pub/Sub client. Follow these steps:

  1. Create a folder named test_client inside the test_client directory. Now, run the following command:
$ npm init -y
  1. Next, install the @google-cloud/pubsub (https://www.npmjs.com/package/@google-cloud/pubsub) module with the help of the following command:
$ npm install @google-cloud/pubsub --save
  1. Create a file inside the test_client folder named index.js and update it as shown in this code snippet:
var PubSub = require('@google-cloud/pubsub'); var projectId = 'pi-iot-project'; var stateSubscriber = 'dht11-data' // Instantiates a client var pubsub = new PubSub({ projectId: ...

Get Enterprise Internet of Things Handbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.