Ideally you'd want to avoid using the Sync versions of these functions as they block the system. Here is an example of how you can write to the file after a read has completed. By passing a function as a callback to be run when the function has completed.
var fs = require("fs");
console.log("starting read...")
fs.readFile("./test.txt", (err,data)=>{
if (err) {console.log(err); return;}
console.log("read is completed.")
console.log(data.toString())
var newdata = "some new data timestamp:"+new Date()
console.log("starting write...")
fs.writeFile("./test.txt", newdata, (err)=>{
if (err) {console.log(err); return;}
console.log("write success")
})
})