can I ask , what is the equivalent for file_put_contents in javascript ?
Thank you in advance.
In JavaScript? No.
In NodeJS? Yes, it's called writeFile
. Here's the example in the documentation:
fs.writeFile('message.txt', 'Hello Node', function (err) { if (err) throw err; console.log('It\'s saved!'); });
Just to add to the reply above if you don't want to overwrite the content of the file but rather append to it
var fs = require('fs'); // don't forget to require in the header or it won't work
fs.writeFile(
"foo.txt", // file
"bar", // string
{
encoding: "utf8",
flag: "a" // flag that specifies that it will append stuff
},
function(){ console.log("done!") }
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With