var fs = require('fs') var Promise = require("bluebird") function file1() { return new Promise((resolve, reject) => { fs.writeFile('cc/file1.txt', 'file1', (err) => { if (err) { throw new Error() } console.log('ok1') resolve('ok1') }) }) } function file2() { return new Promise((resolve, reject) => { fs.writeFile('cc/file2.txt', 'file2', (err) => { if (err) { reject() } console.log('ok2') resolve('ok2') }) }) } function file3() { return new Promise((resolve, reject) => { fs.writeFile('cc/file3.txt', 'file3', (err) => { if (err) { throw new Error() } console.log('ok3') resolve('ok3') }) }) } file1().then(file2).then(file3)