Как мы можем помочь?
< Все темы
Печать

Чтение текстового файла

Синхронно

const fs = require('fs');
const content = fs.readFileSync(path[, options]);

где options = { encoding: 'utf8', flag: 'r' }

Асинхронно

const fs = require('fs');
const content = await fs.readFile(path, "utf-8");

С колбеком

const fs = require('fs');
fs.readFile(path, (error, data) => {
    if (error) {
        return console.log(error);
    }
    console.log(data.toString());
});
Метки:
Оглавление