How to solve multi-layer callback in Node.js

  node.js, question

When learning Node.js, look at the File System on the official website, which has the following code:

fs.rename('/tmp/hello', '/tmp/world', (err) => {
 if (err) throw err;
 fs.stat('/tmp/world', (err, stats) => {
 if (err) throw err;
 console.log(`stats: ${JSON.stringify(stats)}`);
 });
 });

Because fs.stat must be executed after fs.rename, it must be written as a nested fs.stat function in the callback.

The questions are as follows:

  1. Is there a good way to solve this kind of layer-by-layer call, especially when multiple functions are executed sequentially?

Es6′ s promise, I personally feel the best one to use.