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
Also in JavaScript:
- jquery function
- How do you select a particular option in a SELECT element in jQuery?
- javascript replace vowel
- what does componentDidCatch do in react
- encriptar exadecimal con cryptojs
- Underscore.js
- ajax call to load a page on scrolling
- javascript get all instances of a class
- how to toggle class of parent in javascript
- jquery extract number from string
- how to wirte json format
- js clone array
- update json in postgres
- copy link to clipboard
- javascript last item in array
- javascript program german to english translation
- javascript prepend element to array
- javascript appendchild image node
- node js util promisify
- react native get location
- loop through json array python
- checkbox on click jquery
- javascript title string
- add class to html tag javascript