Set up Pulsar Node.js client

Install Node.js client library

Install the pulsar-client library via npm:

  1. npm install pulsar-client

For more information, see README.

Set up - 图1note

This library only works in Node.js 10.x or later versions because it uses the node-addon-api module.

Connect to Pulsar cluster

To connect to Pulsar using client libraries, you need to specify a Pulsar protocol URL.

You can assign Pulsar protocol URLs to specific clusters and use the pulsar scheme. The following is an example of localhost with the default port 6650:

  1. pulsar://localhost:6650

If you have multiple brokers, separate IP:port by commas:

  1. pulsar://localhost:6550,localhost:6651,localhost:6652

If you use mTLS authentication, add +ssl in the scheme:

  1. pulsar+ssl://pulsar.us-west.example.com:6651