Writing JSON object to a file in Node.js

From Logic Wiki
Revision as of 07:45, 9 April 2018 by AliIybar (Talk | contribs) (Created page with "Category:Json Category:Node.js If output is a string, then specify the encoding. and remember the flag options as well.: <pre class="brush:javascript";> const fs = r...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


If output is a string, then specify the encoding. and remember the flag options as well.:

const fs = require('fs');
const content = JSON.stringify(output);

fs.writeFile("/tmp/phraseFreqs.json", content, 'utf8', function (err) {
    if (err) {
        return console.log(err);
    }

    console.log("The file was saved!");
});