How to write a file when using Node.js?

There are a lot of details in the Node.js filesystem API, however the most common way to write a file is:

var fs = require('fs');
fs.writeFile("/tmp/test.txt", "Hello world, this is content!", function(err) {
    if(err) {
        return console.log(err);
    }
 
    console.log("The file was saved!");
});