Код: Выделить всё
import fs from 'node:fs';
function readFilePromise(fileRoute, encoding) {
return new Promise(resolve => resolve(fs.readFileSync(fileRoute, encoding)));
}
let word;
readFilePromise('./data/word.txt', 'utf8')
.then(content => word = content.trim())
.then(console.log('Finished'));
while(word === undefined) {}
console.log(word);
Может быть, этот вопрос очень глуп, я знаю, что могу добавить треть>
Подробнее здесь: https://stackoverflow.com/questions/796 ... ava-thread
Мобильная версия