Connect to Aiven for Apache Kafka® with Node.js
Use Quick connect to set up a Node.js client for Aiven for Apache Kafka®. The guided flow helps you select or create a topic, choose an authentication method, grant permissions, and copy the generated producer and consumer code.
Prerequisites
- A running Aiven for Apache Kafka® service.
- A Node.js development environment.
- The
node-rdkafkalibrary.
Open Quick connect
- In the Aiven Console, open your Aiven for Apache Kafka service.
- On the service Overview page, in the Set up your stream section, click Quick connect.
- At the top of the page, select Node.js from the language selector.
Step 1: Set up a topic
Topics organize and store the events that you stream to Apache Kafka.
-
In Topic name, do one of the following:
- Select an existing topic.
- Click Create new topic, enter a name, and create the topic. The new topic is selected automatically for the next steps.
noteIf your service has Diskless topics enabled, you can create a Classic or Diskless topic, or select an existing topic of either type. You can't change the topic type after creation. For more information, see Create Apache Kafka® topics.
Step 2: Set up an authentication method
-
Select an authentication method:
-
SASL: Recommended. Use SASL/SCRAM-SHA-256 for username and password authentication.
SASL is enabled by default for new Aiven for Apache Kafka services. For existing services, check whether SASL is enabled. If Enable SASL appears, click Enable SASL, then continue.
-
Client certificate: Use certificate-based authentication with mTLS instead of a password.
-
-
Select a service user:
- Select an existing service user from the list.
- To create one, click Create new service user, enter a username, and click Add service user.
-
Check the permission status shown for the selected user:
- If the user has all the required permissions, the granted permissions are
shown (for example,
read, write). To change them, click Manage access in ACLs. - If the user has some or no permissions, click Grant permissions. Select Produce, Consume, or both, and click Save.
noteThe
avnadminuser has permissions by default.For other service users, you can add permissions from Quick connect. To change or remove permissions, click Manage access in ACLs. For more information, see Manage Apache Kafka® ACLs.
- If the user has all the required permissions, the granted permissions are
shown (for example,
Step 3: Copy the code snippets
Download template is an optional shortcut for testing the connection without
a local Node.js environment. The ZIP file includes ready-to-run producer and
consumer code, certificates, and dependencies. To run it, follow the included
README.md. If you already have a Node.js project, copy the snippet from the
Producer or Consumer tab.
-
Install the
node-rdkafkalibrary:npm install node-rdkafka -
Under Downloads, download the certificate files for your authentication method:
- For SASL, click Download CA certificate.
- For Client certificate, click Download CA certificate, Download service certificate, and Download service access key.
For Client certificate, the generated snippet loads the certificates directly. You don't need to create a truststore.
-
Select the Producer or Consumer tab to view the generated producer or consumer code.
-
Copy the code.
noteFor SASL, the snippet includes your service user's password. The console masks it by default; click the reveal icon to view it. The copied code contains the password in plaintext, so store it securely and don't commit it to source control.
After you add the code to your project, update the certificate file paths to match where you saved the files, then run your producer or consumer to start streaming events.