I am new to async / await and promises and such in JS. I am trying to build a small bit of software which actually seems to work. However, one function doesn't finish and seems to run forever without returning a result. Here is my code:
module.exports.visit = (val) => {
let visit_date = Date.now();
let data_json;
let insert;
client.get(val)
.then( (data) => {
data_json = JSON.parse(data);
data_json.count += 1;
data_json.last_visited = visit_date;
insert = JSON.stringify(data_json);
client.set(val,insert);
console.log(insert);
return data_json.url;
})
.catch((err) => {
console.log(err);
});
}
The function calling this function (in order to return the url):
async function visitor() {
// also doesn't work with let a = await helpers.visit('6q9ootm8p7');
let a = helpers.visit('6q9ootm8p7');
return a;
}
visitor();
I would be very thankful if somebody could point me into the same direction.