Back to Yugabyte Db

Build a YugabyteDB application using NodeJS and YEDIS

docs/content/stable/yedis/develop/client-drivers/yedis/nodejs.md

2026.1.0.0-b251.3 KB
Original Source

Installation

Install the NodeJS driver using the following command.

sh
$ npm install redis

Working Example

Prerequisites

This tutorial assumes that you have:

  • installed YugabyteDB, created a universe, and are able to interact with it using the Redis shell. If not, follow the steps in Quick start.
  • installed a recent version of node. If not, you can find install instructions here.

Write the HelloWorld NodeJS application

Create a file yb-redis-helloworld.js and add the following content to it.

js
const redis = require("redis")
const client = redis.createClient();

client.on("error", function (err) {
    console.log("Error " + err);
});

// Insert the user profile.
const userid = 1
client.hmset(userid, ["name", "John", "age", "35", "language", "NodeJS"], redis.print);

// Query the user profile.
client.hmget(userid, ["name", "age", "language"], redis.print);

// Close the client.
client.quit(function (err, res) {
    console.log('Exiting from quit command.');
});

Run the application

To run the application, type the following:

sh
$ node yb-redis-helloworld.js

You should see the following output.

Reply: OK
Reply: John,35,NodeJS
Exiting from quit command.