I'm new to Node js Promise I'm not sure whether I'm using the Promise correctly or not so here is my code.
function print(){ first('first') .then(second('second')) .then(third('third')); } function first(a){ return new Promise((resolve, reject) => { var res1 = function (){ resolve(a); } }); console.log(a); } function second(b){ return new Promise((resolve, reject) => { var res1 = function (){ resolve(b); } }); setTimeout(() => { console.log(b); }, 2000); } function third(c){ return new Promise((resolve, reject) => { var res1 = function (){ resolve(c); } }); console.log(c); } My desired output is
first second third Instead what I get is
first third //after two seconds second I'm missing something but I can't figure it out please explain me