Overwrite a File in Node.js : <p>Im trying to write into a text file in node.js.
Im doing this the following way:</p>

<pre><code>fs.writeFile("persistence\\announce.txt", string, function (err) {
    if (err) {
        return console.log("Error writing file: " + err);
    }
});
</code></pre>

<p>whereas string is a variable. </p>

<p>This function will begin it`s writing always at the beginning of a file, so it will overwrite previous content. </p>

<p>I have a problem in the following case:</p>

<p>old content:</p>

<pre><code>Hello Stackoverflow
</code></pre>

<p>new write:</p>

<pre><code>Hi Stackoverflow
</code></pre>

<p>Now the following content will be in the file:</p>

<pre><code>Hi stackoverflowlow
</code></pre>

<p>The new write was shorter then the previous content, so part of the old content is still persistent.</p>

<p><strong>My question:</strong></p>

<p>What do I need to do, so that the old content of a file will be completely removed before the new write is made?</p>
