node-jq icon indicating copy to clipboard operation
node-jq copied to clipboard

[Question] Can node-jq run synchronous?

Open danimesq opened this issue 4 years ago • 1 comments

The 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()?

@sanack @davesnx

danimesq avatar Sep 21 '21 21:09 danimesq

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!

davesnx avatar Nov 15 '21 15:11 davesnx

@davesnx

Do you have any reason why it shouldn't be an async call?

Some people would much prefer to just write synchronous JS and cannot utilize this package at all without sync support?

RulerOf avatar Sep 28 '22 05:09 RulerOf

Hi @RulerOf

The "sync" support is very easy to add, not so easy to maintain but PR are welcome. If some people prefer it, I'm happy to help land the feature and commit to maintaining it, but I doubt that you would prefer to interact with a shell command synchronously.

The issue has been open for 1 year and without a clear use case or answer.

Closing it (for now) If there's a need happy to re-open

davesnx avatar Sep 28 '22 06:09 davesnx

This is a much-needed feature.

AllSeeingEye avatar Dec 07 '22 05:12 AllSeeingEye

If it's than needed. I'm happy to receive a contribution with this addition

davesnx avatar Dec 07 '22 08:12 davesnx