0

I was building a real-time chat app. I am using express-session to add cookies so that users don't have to login every time page refreshes.

const session = require("express-session");
const Redis = require("ioredis");
const RedisStore = require("connect-redis")(session);

This is my import. I have more but I think these are related to the problem so I am sharing only these. And I have all of this downloader in my project in case anyone says to double check if I installed them properly or not that's why I am adding this. This is how I was implementing the code ...

const redisClient = new Redis();
app.use(session({
    secret:process.env.COOKIE_SECRET,
    credentials:true,
    name:"$id",
    store: new RedisStore({client:redisClient}), //This is the user's session information
    resave:false,
    saveUninitialized:false,
    cookie: {
        secure:process.env.ENVIRONMENT === "production" ? "true" : "auto",
        httpOnly:true,
        expires: 1000 * 60 * 60 * 24 * 7,
        sameSite:process.env.ENVIRONMENT === "production" ? "none" : "lax",
    }
}))

But I keep this error message that require(...) is not a function. I tried to solve it but I couldn't.

I tried to install redis instead of ioredis to see if this solves but it did not.

  • Does this answer your question? [NodeJs : TypeError: require(...) is not a function](https://stackoverflow.com/questions/33007878/nodejs-typeerror-require-is-not-a-function) – Moshe Fortgang Jul 09 '23 at 12:04
  • I checked the express-session in the node modules. And it is class. I cannot change it to function because everything will break. – Nabil Ahmed Jul 09 '23 at 14:42

0 Answers0