[Question] Can node-jq run synchronous?
See original GitHub issueThe username NPM package enables me to just use username()
to get a result.
I would like that node-jq could be that simple, by just using something like jq.run("'.abilities[].moves' /path/to/bulbasaur.json")
(using the same standard as jq in the shell) in one line and directly return (instead of console.log
) the result. Just like the username package does.
username()
works pretty well and is still asynchronous (as in their docs).
Doesn’t relies on console.log
. Is pretty standard.
This may not be only a question, but also a suggestion.
const jq = require(‘node-jq’)
Is only declared once, so it isn’t part of the example.
So, should I declare:
const filter = ‘.abilities[].moves’ const jsonPath = ‘/path/to/bulbasaur.json’ const options = {}
everytime?
Have:
jq.run(filter, jsonPath, options) .then((output) => { console.log(output) }) .catch((err) => { console.error(err) })
to be that big? And to necessarily use console.log
and not being fireable in one-line like username()
?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
@davesnx
Some people would much prefer to just write synchronous JS and cannot utilize this package at all without sync support?
Hey @DaniellMesquita
Node-jq runs jq in the terminal with child_process, which can either run async or sync. Right now, node-jq just expose an asnyc version of the operation.
Do you have any reason why it shouldn’t be an async call? Also, happy to help landing a contribution here if you are interested.
Thanks for asking those questions!