save text to file nodejs
fs = require('fs');
fs.writeFile(filename, data, [encoding], [callback])
save text to file nodejs
fs = require('fs');
fs.writeFile(filename, data, [encoding], [callback])
node js write read string to file
// basic read-write string from-to file with node.js
var fs = require('fs');
var opath = 'test.txt';
var ostring = 'Hello!'
fs.writeFileSync(opath, ostring, 'utf8');
var istring = fs.readFileSync('test.txt').toString();
console.log(istring);
// with error handling and logging:
fs.readFile('test.txt', 'utf8' , (err, data) => {
if (err) {
console.error(err)
return
}
console.log(data)
});
// or fs.readFileSync() or use streams for large files
// for better memory consumption and execution speed
// https://nodejs.dev/learn/reading-files-with-nodejs
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us