Request object appears in result

Why request object appears in result console?

const request = require('request')

var uri = 'http://v2.convertapi.com/token/create?secret=nop'

request.post(uri, function(err, response, body) {
    console.log(JSON.parse(response.body)) 
})

RunKit captures and displays the result of the last expression in a cell. In this example the last expression is the result of request.post(), which apparently returns the request object.

You could also do 1+1 at the end of a cell and see 2, even though you didn’t explicitly log it. Basically, it works the same as your regular Node REPL.

RunKit captures and displays the result of the last expression in a cell.

This is not so easy to do when NodeJS propose asynchronous programming. I see no way to do that using request module because it’s not implements promises and do not support await.

I am new to JSNode things, maybe you have idea how to “hide” request object and only display response?

Hi convertapi,

What you want to do is use a library that supports async/await. For example, got:

var got = require("got");

(await got.post('http://v2.convertapi.com/token/create?secret=nop'), { json: true }).body;

This will do exactly what you want and fetch the data but wait to display the result.

Let me know if you need any more help!

Thanks,

Francisco