DEV Community

Vahe
Vahe

Posted on

Turn any callback into promise with babel-plugin-promise

briefly,I will tell you how to convert an existing callback to promise.

We will need to use babel.

For example, let's take a request from npm and convert it to a promise

yarn add babel-plugin-promise --dev
Enter fullscreen mode Exit fullscreen mode
require("babel-polyfill");

import request from "request";

//@promisify<err,res> req
__ = request(arg1);

console.log(req("http://www.google.com"));

req("http://www.google.com")
    .then(res => console.log(res.body.length))
    .catch(err => console.log(err));

Enter fullscreen mode Exit fullscreen mode

let's check

quite quickly

babel-plugin-promise

Top comments (0)