node open file
// load fs
const fs = require("fs");
// read the file
const content = fs.readFileSync("./my_file.txt");
// print it
console.log(content.toString());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());
});var content;
fs.readFile('./Index.html', function read(err, data) {
if (err) {
throw err;
}
content = data;
});
console.log(content);fs = require('fs')
fs.readFile('/etc/hosts', 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
console.log(data);
});
Also in JavaScript:
- javascript access property values list of objects
- hgow to hide scroll bar and add buttons in javascript
- js tostring
- json beautify
- classic asp get json from url
- js fit window to content
- table like another component in react native
- javascript detect escape key pressed
- array alphabet
- how to run an express app
- find element in array underscore js
- react change state
- js get file name from path
- send audio with socket io node js
- axios get array of urls
- uuid v4 react
- what is console in javascript
- mute everyone in call discord.js
- axios react post form data
- javascript change image src
- disable input angular
- how to convert char to number in js
- get text in select jquery
- redux devtools with middleware