readfile nodejs
const fs = require("fs");
// __dirname means relative to script. Use "./data.txt" if you want it relative to execution path.
fs.readFile(__dirname + "/data.txt", (error, data) => {
if(error) {
throw error;
}
console.log(data.toString());
});const fs = require('fs');
fs.readFile('/Users/joe/test.txt', 'utf8' , (err, data) => {
if (err) {
console.error(err);
return
}
console.log(data);
});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
})var content;
fs.readFile('./Index.html', function read(err, data) {
if (err) {
throw err;
}
content = data;
});
console.log(content);fs.readFile('filename', function read(err, data) {
if (err) {
throw err;
}
var content = data;
console.log(content);
});fs.readFile('/etc/passwd', (err, data) => {
if (err) throw err;
console.log(data);
});
Also in JavaScript:
- vue watch deep
- how to Check if an array contains a string
- what is package.json
- jquery continue in loop each
- how to check the listeners on an object js
- javascript dictionary
- flutter use valuechanged function in function
- javascript get middle of array
- mongoos populate a ref
- cdnjs smeantic ui
- how to clear pod cache in react native
- materialize for react
- splice from array javascript to remove
- js check if string contains character
- javascript define global variable
- get data from column in table js
- react router redirect
- input radio trigger select jquery
- usestate() react
- How to check if a member has a role discord.js
- google script range get cell values
- react create list of array in react
- downloadable custom pdf for node
- express and node pakages