Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

UnhandledPromiseRejectionWarning

Quando tento rodar com o node acontece esse erro: UnhandledPromiseRejectionWarning

O código abaixo tem algo de errado?

import fs from 'fs';
import chalk from 'chalk';

function trataErro(erro) {
    throw new Error(chalk.red(erro.code, 'Oops!'));
}

function pegaArquivo(caminhoDoArquivo) {
    const encoding = 'utf-8';
    fs.promises
    .readFile(caminhoDoArquivo, encoding)
    .then((texto) => chalk.blue(console.log(texto)))
    .catch((erro) => trataErro(erro))
}

pegaArquivo('./arquivos/texto1.md');
1 resposta
solução!

Já consegui resolver!