write in a file js code example
Example 1: fs writefile node
const fs = require('fs')
const content = 'Some content!'
fs.writeFile('/Users/joe/test.txt', content, err => {
if (err) {
console.error(err)
return
}
//file written successfully
})
Example 2: writing files in javascript
'use strict'
const fs = require('fs');
let fileContent = 'I can write';
fs.writeFileSync('message.txt', fileContent);