nodejs 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.readFile('filename', function read(err, data) {
if (err) {
throw err;
}
var 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:
- ajax
- discord.js check for permissions
- insertion sort javascript
- node js server
- javjquery is emptyobject
- jquery is not defined rails
- javascript pop object from array
- TextInput disable react native
- constant arrays in javascript
- DECIMAL TO BINARY CONVERSION javascript
- python http request post json example
- javascript generate function dynamically
- what is data type in javascript
- postfix date javascript
- how to get a bot online on discord
- begins_with node js AWS dynamodb sort key
- how to lose overflow in js without hidden
- object javascript match by property value
- fetch and then javascript send parameters
- jquery form id submit
- regular expression flags
- how to fill array with consecutive numbers javascript
- npm
- json search javascript