I'm learning NodeJS. One thing I'm finding really annoying is when working with promises from an interactive console while debugging and/or just poking around at the interfaces of various libraries. The work flow is normally; call some library to do some work, wait for result, poke around at the result to see how it actually behaves and looks like.
For example (and just for example) I want to interactively inspect the image data structure returned from Jimp. I'm finding myself doing this from the console:
const Jimp = require('jimp');
const fs = require('fs');
let data = fs.readFileSync('path/to/my/test/images')
let image = null
Jimp.read(data).then((result, error) => { image = result; });
// Work with image here ...
This boiler plate gets annoying to write .. I think I missed a trick. Is there a more convenient way around this? A setting can set, or a library I can load or something?
I'd rather do this:
...
let image = await Jimp.read(data);
// Work with image here ...
But this gives "SyntaxError: await is only valid in async function". Or if not that, then maybe:
...
let image = resolveMe(Jimp.read(data))
// Work with image here ...
P.S. "async / await" is not an answer to this question. In order for an async function to be evaluated you have to give control back to the event loop, and you can't do that at an interactive prompt currently AFAIK.