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:
- Create a folder named test_client inside the test_client directory. Now, run the following command:
$ npm init -y
- 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
- 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: ...