Clash Royale CLAN TAG #URR8PPP .everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0; up vote 4 down vote favorite Using javascript functions and the old way of doing things I wrote a piece of code to copy the first file in a directory to a file Test . console.log("Copy First File"); var fs = require('fs'); fs.readdir(".", function(err, files) if (err) console.log(err);process.exit(1); fs.exists(files[0], function(exits) fs.readFile(files[0], function(err, data) if (err) console.log(err);process.exit(1); fs.writeFile('Test', data, function(err) if (err) console.log(err);process.exit(1); console.log("Data Copied"); ); ) ); ); After reading about Promises (and several failed attempts). I managed to convert the above to use Promise and .then() chaining. function getAListOfFiles() return new Promise(function(resolve, reject) fs.readdir(".", function(err, files) if (err)...