Closed
Description
I've seen this requested a few times in StackOverflow now:
People have code that is asynchronous and would like to use values from it in the REPL:
// how do I access in the REPL? returns promise
Transaction.where('reference', '1').fetch().then((res) => { return res });
A common workaround is to store a global reference in the REPL, which is a little hacky and relies on timing, but can work for simple cases:
> Transaction.where('reference', '1').fetch().then((res) => out = res)
[Object Promise]
> out
/* response available here*/
This works, but has timing issues and generally isn't great. We could however run the REPL in the context of an async function potentially - which would allow await
ing values in the REPL:
let res = await Transaction.where('reference', '1').fetch();
I think it could be an interesting enhancement but would like more feedback on the idea. @nodejs/collaborators