Javascript covert Callback to Promise to Async/Await

const fs = require("fs");
fs.readFile(".env", (err, data) => {
console.log(err); console.log(data);});
const fs = require("fs");new Promise((resolve, reject) => {  fs.readFile(".env", (err, data) => {    if (err) return reject(err);    return resolve(data);  });}).then((data) => {  console.log("data", data);}).catch((err) => {  console.log("Err", err);});
const fs = require("fs");
const
getData = () => {
return new Promise((resolve, reject) => { fs.readFile(".env", (err, data) => { if (err) return reject(err); return resolve(data); }); });};(async () => { try { const data = await getData(); console.log("getData", data);} catch (e) { console.log("getData Err", e);}})();

Need Help? Contact me.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store