Unable to instantiate the node redis client

I encountered an issue while trying to start my node application, and I received the following error message:

TypeError: redisClient.on is not a function

The problem seems to be related to the RedisClient module:

      const redisClient = require('redis').createClient({
      socket: {
        host: process.env.REDIS_HOST,
        port: process.env.REDIS_PORT,
      },
      password: process.env.REDIS_PASSWORD,
    });
        
        module.exports.redisClient = redisClient;
    

In the block of code that fails, this is what it looks like:

    exports.connectRedis = async () => {
      redisClient.on('ready', () => {
        console.log('Connected to Redis');
      });
    
      redisClient.on('error', (err) => {
        console.log('Error in the Redis connection:', err.message);
      });
    
      await redisClient.connect();
    };

Initially, everything was functioning well until I installed 'redis-mock'. Although I have removed this package, the issue persists.

My current versions are Redis 4.6.4 and Node 19.1.0. Could there be a conflict between these versions?

Thank you for your assistance.

Answer №1

After some tweaking, I managed to resolve the issue by adjusting the client module like this:

module.exports = require('redis').createClient({
  socket: {
    host: process.env.REDIS_HOST,
    port: process.env.REDIS_PORT,
  },
  password: process.env.REDIS_PASSWORD,
}); 

Interestingly, I ditched using a const declaration and encountered issues - still trying to figure out why...

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

It appears that the NodeJs Express 4 async function in the model is returning before completion

I'm currently working on organizing my project by splitting the logic into different folders such as routes, views, models, and controllers. Within a model named data (models/datamodel.js), I have implemented two methods to retrieve data for populati ...

Modifying the attribute of an element inside an array

Presented below is an object: { "_id" : ObjectId("5a8d83d5d5048f1c9ae877a8"), "websites" : [ "", "", "" ], "keys" : [ { "_id" : ObjectId("5a8d83d5d5048f1c9ae877af"), "name ...

Configurable BaseUrl in an ExpressJs Application

One issue I am currently facing is setting the base URL for an Express app when it starts up. If I hardcode the base URL, everything works perfectly: app.use("/mybaseurl", routes); However, when I attempt to use a variable that I export at startup, it d ...

How to effectively execute AJAX requests on the server side using Node.js

I am currently in the process of developing a search engine that utilizes both Twitter and Wiki APIs on the server-side after receiving a search query from the client. Previously, when operating solely on the client-side, my AJAX request to the Wiki API lo ...

Should Redux Reducer deep compare values or should it be done in the Component's ShouldComponentUpdate function?

Within my React Redux application, I have implemented a setInterval() function that continuously calls an action creator this.props.getLatestNews(), which in turn queries a REST API endpoint. Upon receiving the API response (an array of objects), the actio ...

After using browserify, when attempting to call the function in the browser, an Uncaught ReferenceError occurs

I am currently in the process of creating a compact NPM package. Here is a basic prototype: function bar() { return 'bar'; } module.exports = bar; This package is meant to be compatible with web browsers as well. To achieve this, I have inst ...

Achieving secure HTTPS connection with socket.io

At the moment, my setup involves: let connectTo = "http://myip:myport"; var socket = io.connect(connectTo, {secure: true}); on the client side and const port = myport; const io = require('socket.io')(port); on the server side. I am looking to ...

What steps are involved in setting up role-based authentication using Node.js?

Essentially, I am looking for a way for nodeJS to determine if the user logging in through the login page is an admin or not. If they are an admin, they should be directed to the admin page; if not, they should be sent to a different page. Currently, I ha ...

Spreading out across various tiers proves to be ineffective

I've encountered a challenge with my blog model that contains multiple comments with nested replies. So far, I have only been able to access the first two layers of these comments. Here is an example of how this data is stored in my database as Comme ...

Leveraging node.js for website development

After setting up Node.js and installing the latest version of Express 3.4.1, I started coding. However, when trying to send parameters other than /, I encountered an error. In my index.js file, I have the following code: exports.speakers = function(req, ...

Troubleshooting cross-origin resource sharing problem with Express NodeJS server running on localhost

Utilizing the fetch web API to send a POST request from ReactJS to an Express NodeJS server running on localhost with different ports. Using Client Fetch API fetch("http://localhost:8081/test", { method: "post", mode:"no-cors", headers: { ...

Upon deployment, Dokku mistakenly categorizes my Node.js application as a Go app

After creating a Procfile with the following contents: web: node web.js I updated my package.json file as follows: { "name": "app-express", "version": "0.0.1", "private": true, "description": "web panel", "main": "web.js", "scrip ...

AJAX: Displaying the contents of a folder. Issue with URL resolution

I'm attempting to showcase a collection of images stored in a specific folder within a div. My approach involves utilizing AJAX within a JavaScript file titled edit, which is positioned one directory away from the index route. This implementation is b ...

How can I utilize angular's $http service to fetch a JavaScript file?

I've been exploring the integration of Angular with Node.js and attempting to establish a connection to a MySQL database. Within my script (server.js), I am utilizing the node mysql module as shown below: var mysql=require('mysql'); var ...

Using TypeScript in conjunction with Node.js

I'm currently trying to use typescript with nodejs, but I keep encountering errors. Can anyone help me troubleshoot? Here is the code snippet (assuming all necessary modules are imported): import routes from "./routes/routes"; let app = express(); ap ...

Is it possible to extract all parameters, including nested or within arrays, from a Swagger File using Node.js?

Looking for a method to extract and interpret data such as parameters from a Swagger file. Specifically, I am working with the Petstore Swagger API ( ). The definitions within the file contain references to other components, like parameters. One example ...

What is the most effective way to constantly decrease my count by 1 each day within a MongoDB document?

I have a MongoDB document structured as shown below: { id: "someId" useEmail: "someEmail" membershipDaysLeft: 30 } My goal is to decrement the value of membershipDaysLeft by 1 each day until it reaches 0. What would be the most e ...

What is the purpose of NPM including an empty "etc" directory and multiple command files during installation?

After updating or installing a package in my project, I've noticed that NPM is creating an empty etc folder and multiple .cmd files (refer to image below). Additionally, my package.json file is not being updated automatically anymore. I have to manual ...

Are you ensuring compliance with licensing in your Webpack bundles?

Can webpack be used to verify license compliance? I'm looking for a way to ensure that the license headers from all modules built by webpack are included in the final output file. How can we confirm this is happening? Furthermore, I am also intereste ...

Exploring the depths of nested relationships in Bookshelf.js

I'm in the process of developing an app similar to Reddit. Each topic has comments, which may have parent comments and so on. Below is my Comment model: var Comment = bookshelf.Model.extend({ tableName: 'comments', topic: function() { ...