there is a variable that is passed to the function
var relsi; and if the variable is 1 , then the function performs one action, if the variable is 2 , then the other actions. and the problem is that after performing some actions, it redirects to another function, which changes the value of relsi and starts the timer to perform other setTimeout actions, but in the end the timer does not work and this action is executed immediately.
function mybackpack() { save = []; var name = []; var item_id = []; backpack = []; var url = 'google.com'; request(url, function(err, res, body){ if(err){console.log(err);} else{ неважно что тут }); if(Relsi === 1) { fs.writeFileSync('./app/data.json', JSON.stringify(backpack, null, 4)); StartSell() } if(Relsi === 2) { CreateOrders() } }; }); }