JS
copy
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
})
const fs = require('fs')
const content = 'Some content!'
try {
fs.writeFileSync('/Users/joe/test.txt', content)
//file written successfully
} catch (err) {
console.error(err)
}
fs = require('fs');
fs.writeFile(filename, data, [encoding], [callback])