I have created an Express 2.x app using the CLI. So I have a routes directory and an index.js.
Now, in app.js, I have connected to Redis, and it works properly.
I call the function in the routes/index.js file from app.js here:
app.post('/signup', routes.myroute);
The myroute function contains code to get a key from Redis.
Now, I get the error that redis is not defined.
How do I pass the redis object into routes/index.js from the app.js?
Easiest Solution
You probably have a require() function that includes a redis lib in your app.js. Just take that line and add it to the top of your index.js file.
if you are using the node_redis module, simply include this:
Alternative Approach
If you are looking to reuse the existing connection, try passing the
clientvariable to the function in index.js:app.js
index.js