You can use node in nightwatch, as a matter of fact.
You can do what you have described using a custom command. In the custom_commands folder create say, helperFunctions.js, which looks like this:
var fs = require('fs'); // NPM to create a file
module.exports = {
saveToFile : function(client, data, path){
this.fs = fs;
buffer = new Buffer(data);
// the path here is the directory to your xls file and the file name
fs.open(path, 'w', function(err, fd) {
if (err) {
throw 'error opening file: ' + err;
}
// write the data
fs.write(fd, buffer, 0, buffer.length, null, function(err){
if (err) throw 'error writing file: ' + err;
return fs.close(fd, function() {
// great place to put a console.log to indicate success
console.log('File created / updated ' + filename)
})
});
})
}
};
Then you can call save to file from your regular test suite like so:
"Save excel data to a file for later use": function(client) {
client
// where data is a variable with whatever data you want in the file.
this.helperFunctions.saveToFile(client, data, "conf/MyExcelData.xlsx")
},
You may need to play around with this a bit to get it to do what you want, but rest assured, I have done it with text and js files and I know of no reason this cannot be done with any file data that will fit into a buffer.