showing results for - "promisify a callback"
Diego Alejandro
04 Feb 2017
1const fs = require('fs');
2
3const readFile = (fileName, encoding) => {
4    return new Promise((resolve, reject) => {
5        fs.readFile(fileName, encoding, (err, data) => {
6            if (err) {
7                return reject(err);
8            }
9
10            resolve(data);
11        });
12    });
13}
14
15readFile('./sample.txt')
16    .then(data => {
17        console.log(data);
18    })
19    .catch(err => {
20        console.log(err);
21    });
22