readfilesync
const fs = require('fs')
try {
const data = fs.readFileSync('/Users/joe/test.txt', 'utf8')
console.log(data)
} catch (err) {
console.error(err)
}
readfilesync
const fs = require('fs')
try {
const data = fs.readFileSync('/Users/joe/test.txt', 'utf8')
console.log(data)
} catch (err) {
console.error(err)
}
nodejs readfile
const fs = require('fs');
fs.readFile('/Users/joe/test.txt', 'utf8' , (err, data) => {
if (err) {
console.error(err);
return
}
console.log(data);
});
node readFileSync json
const fs = require('fs');
let rawdata = fs.readFileSync('student.json');
let student = JSON.parse(rawdata);
console.log(student);
node read file sync
// macOS, Linux, and Windows
fs.readFileSync('<directory>');
// => [Error: EISDIR: illegal operation on a directory, read <directory>]
// FreeBSD
fs.readFileSync('<directory>'); // => <data>
fs.readfile
fs.readFile('filename', function read(err, data) {
if (err) {
throw err;
}
var content = data;
console.log(content);
});
fs.readfilesync withFileTypes true
_(fs.readdirSync(baseDir, {withFileTypes: true}))
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name)
.concat('.')
.map(directory => path.resolve(baseDir, directory, '.platform.app.yaml'))
.filter(file => fs.existsSync(file))
.map(file => ({data: yamlPlatform.load(fs.readFileSync(file)), file}))
.map(data => ({name: data.data.name, file: data.file, dir: path.dirname(data.file)}))
.value()
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us