Promise.resolve()
.then(() => {
console.log("p1");
process.nextTick(() => console.log("n2"));
})
.then(() => console.log("p2"));
process.nextTick(() => console.log("n1"));
n1 p1 p2 n2
"n1 p1 p2 n2" is correct. After the script, the nextTick queue runs first and logs n1. Then V8 empties the whole promise microtask queue. This includes p2, which is added to the queue while V8 is emptying it. Node checks the nextTick queue again only after the microtask queue is empty. So n2 comes last.
"n1 p1 n2 p2" is wrong. A tick scheduled inside a promise callback does not jump ahead of the rest of the promise chain.