fs.writeFile() writes [object, object] instead of actual objects when closing script
<p>My script needs to read and write from a JSON file. This works without problems.
I copy the file locally, edit the object, and write them back out to the file.
However, when I close the script with Ctrl+C and check my file it has <code>[object, object]</code> instead of the actual objects that should be there.
This doesn't happen all every time, but is annoying because my script depends on this file.</p>

<p>Any ideas for how to prevent this from closing the reader incorrectly?
I already tried checking the type before writing but it didn't seem to help much.</p>

<pre><code>function writeConfig(obj) {
    fs.writeFile('./config.json', obj, function (err) {
        if (err) console.log(err);
    });
}
</code></pre>