let arra = ['111', '222', '333', '444']
function deley (iterator) {
let i = iterator || 0;
setTimeout(function () {
console.log(arra[i]);
i++;
if(i < arra.length){
deley(i)
}
}, 2000);
}
deley();
async (req, res) => {
...
try {
let article = await newArticle.save();
let section = await Section.findOneAndUpdate({ _id: article.section }, {$push: {"articles": article._id}}, {new: true});
if (section === null) return res.json({ message: 'No sections found' });
res.status(201).json({
status: 'OK',
article
});
}
catch(e) {
console.log(e);
next(e);
}