question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] Can node-jq run synchronous?

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
RulerOfcommented, Sep 28, 2022

@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?

1reaction
davesnxcommented, Nov 15, 2021

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I do it synchronously in node js - Stack Overflow
js and I want the code below run synchronously. I want to move the DB to another place but I need to wait...
Read more >
How to execute an array of synchronous and asynchronous ...
We have an array of functions, some functions will be synchronous and some will be asynchronous. We will learn how to execute all...
Read more >
Overview of Blocking vs Non-Blocking - Node.js
Blocking methods execute synchronously and non-blocking methods execute asynchronously. Using the File System module as an example, this is a synchronous ...
Read more >
Node.js: what it is, when and how to use it, and why you should
Synchronous (or sync) execution usually refers to code executing in sequence. In sync programming, the program is executed line by line, one ...
Read more >
Introducing asynchronous JavaScript - Learn web development
In this article, we'll start by looking at the problem with long-running synchronous functions, which make asynchronous programming a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found