Write log file in nodeJS with setInterval
I'm assuming that you are changing the logText variable to control what's being logged. If you want to keep this same interface, the only optimization that I can see is to make log() check if logText is not empty before it writes it:

var fs = require('fs');
var logText = '';
function writelog(){
    if (logText) {
        fs.appendFile('c:/log.txt', logText, (err) =&gt; {
            if (err) throw err;
            logText = '';
        });
    }
}
setInterval(writelog, 5000);


I would also add a function that adds to the log text:

function log(text){
    logtext += ("Log prefix stuff here" + text)
}