Answer the question
In order to leave comments, you need to log in
How to write data to object from fs function in javascript?
There is such a code. I want to pass data from fs.stat and write it to a variable, but I don't quite understand how to do it. If you just output the entire object to the console, then the information is displayed, but if you refer to a specific element, it is empty. Tell me how you can display data from fs.stat? And you can do something like return data?
var folders2 = {
items: []
}
fs.stat('D:\\MEGA\\Завершенные скрипты\\AppInstaller\\apps\\Архиваторы', function (err, stats) {
if (stats.isFile()) {
type = 'file'
}
if (stats.isDirectory()) {
type = 'directory'
}
folders2.items[0] = {
ext: type,
type: type
}
folders2.items[1] = {
ext: type,
type: type
}
});
console.log(folders2.items) // а тут есть
console.log(folders2.items[0]) // пусто
console.log(folders2.items[0].type) // пусто
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question