Answers for "fs.readdirSync"

4

fs.readdirSync nodejs

The fs.readdirSync() method is used to synchronously read the contents
of a given directory.
The method returns an array with all the file names 
or objects in the directory. The options argument can be used to change the
format in which the files are returned from the method.

fs.readdirSync( path, options )
Posted by: Guest on August-11-2021
11

fs.writefile

const fs = require('fs');

fs.writeFile("/tmp/test", "Hey there!", function(err) {
    if(err) {
        return console.log(err);
    }
    console.log("The file was saved!");
}); 

// Or
fs.writeFileSync('/tmp/test-sync', 'Hey there!');
Posted by: Guest on August-08-2020
7

nodejs readfile

const fs = require('fs');

fs.readFile('/Users/joe/test.txt', 'utf8' , (err, data) => {
  if (err) {
    console.error(err);
    return
  }
  console.log(data);
});
Posted by: Guest on August-30-2020
4

nodejs readdir

const fs = require("fs")
fs.readdir("./myfolder", (err, data) => {
	if(err) throw err
  	console.log(data)
})
Posted by: Guest on November-28-2020
0

fs readfile encoding

fs.readFile('/etc/passwd', 'utf8', callback);
Posted by: Guest on April-17-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language