Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

read file node

// load fs
const fs = require("fs");
// read the file
const content = fs.readFileSync("./my_file.txt");
// print it
console.log(content.toString());
Comment

node open file

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());
});
Comment

read a file nodejs

const fs = require('fs');

fs.readFile('my-file.txt', 'utf8', function(err, data) {
    if (err) throw err;
    console.log(data);
});
Comment

Reading files with Node.js

JS
copy
const fs = require('fs')

fs.readFile('/Users/joe/test.txt', 'utf8' , (err, data) => {
  if (err) {
    console.error(err)
    return
  }
  console.log(data)
})
Comment

nodejs open file

fs = require('fs')
fs.readFile('/etc/hosts', 'utf8', function (err,data) {
  if (err) {
    return console.log(err);
  }
  console.log(data);
});
Comment

read files in node js

const fs = require("fs");
const text = fs.readFileSync("dele.txt", "utf-8")
console.log("The content of the file is")
console.log(text);
Comment

how to read files in node

var http = require('http');
var fs = require('fs');
http.createServer(function (req, res) {
  fs.readFile('index.html', function(err, data) {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.write(data);
    return res.end();
  });
}).listen(8080);
Comment

open file method in node js

var fs = require("fs");
  
// Asynchronous - Open File
console.log("opening file!");
fs.open('input.txt', 'r+', function(err, fd) {
   if (err) {
      return console.error(err);
   }
   console.log("File open successfully");     
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: js compare 2 arrays for unique values 
Javascript :: angular MatDialogRef spec 
Javascript :: shadowoffset react native constructor 
Javascript :: onpress image react native 
Javascript :: uuid v4 
Javascript :: fill array with random numbers javascript 
Javascript :: How to change htm h1 from nodejs 
Javascript :: hide element js 
Javascript :: add search query in express 
Javascript :: how to set validation for email in javascript 
Javascript :: node crypto hmac sha256 
Javascript :: auto comoplete off in vu js 
Javascript :: get all keys of object in javascript 
Javascript :: adonis andwhere 
Javascript :: Nazmul 
Javascript :: check if there is data in localstorage 
Javascript :: how to run method in method vue js on load 
Javascript :: how to change the color using js 
Javascript :: js loop every x seconds 
Javascript :: access laravel eloquent relation in js 
Javascript :: moment + 1 day 
Javascript :: How to save input from box html 
Javascript :: get attribute href 
Javascript :: get first property from object javascript 
Javascript :: js redirect to another page 
Javascript :: jq get by name 
Javascript :: regex check from a-z 0-9 
Javascript :: js on dom content loaded 
Javascript :: flatlist listemptycomponent center 
Javascript :: select random from an array 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =