Brief
I'm trying to import a file containing redundant's code in consumers. So far it seems my file is doesn't read by the consumer which returns me:
function getAsync is not defined
but it however defined in file1.js
Here my snippet:
file1.js:
const redis=require("redis");
rejson = require('redis-rejson');
const {promisify} = require('util');
rejson(redis); /* important - this must come BEFORE creating the client */
let client= redis.createClient({
port:6380,
host:'localhost',
// password:process.env.rPass
});
const setAsync = promisify(client.json_set).bind(client);
const arrappendAsync = promisify(client.json_arrappend).bind(client);
const getAsync = promisify(client.json_get).bind(client);
const existsAsync= promisify(client.exists).bind(client);
file2.js:
require("./redisConnect")
async function getUser(){
let res=await getAsync("userStock", ".")
.catch((err) => console.error(err));
resArray= JSON.parse(res)
console.log("userStock res: ", resArray[0]);
client.quit()
}
// use userId to filter relevant array
getUser()
So how handle this situation?
Any hint would be great, thanks