How to get a synchronuous result from an HTTP request in node.js

uli_1973

I am writing a node module as a wrapper around a Python module (to make that module available from node.js). This module works as a standalone script or as an HTTP server.

When getting data from that script/server my function needs to return a value and can't do something in a callback function. At least that's how I understand it.
(One possible client is a gitbook-plugin, and when that encounters a "block" it has to call the plugin->my-client-module and insert its return value into the generated HTML document.)

So either I'm seeing something wrong because I'm too new to Node.js (coming from Python) or I need a way to make the HTTP request synchronous.

With the standalone script I can easily do it using ChildProcess.spawnSync, but not in an HTTP request.

Well, I know people are always recommending to do things asynchronously in Node, so I'd also be happy about pointers how to achieve my goal that way. As said I expect clients of my module to pass me some data, pass that along to invoke the script or do a POST request on the server and return the processed data to the client.

user4244405

You can achieve synchronous HTTP requests using web-workers.
Here is more info on this topic:
https://developer.mozilla.org/zh-TW/docs/Web/API/XMLHttpRequest/Synchronous_and_Asynchronous_Requests#Example_Synchronous_HTTP_request_from_a_Worker


Edit:

You can make synchronous requests from Node.Js. The following module should help: https://www.npmjs.com/package/sync-request

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to get data out of a Node.js http get request

From Dev

How to return ArrayBuffer from $http request in Node.js?

From Dev

how to get the value from request.get in node js

From Dev

How can I get the http request headers actually sent by me in node.js http request

From Dev

How can I get the http request headers actually sent by me in node.js http request

From Dev

how to get key value from json result in node js

From Dev

HTTP GET request with parameters Node.js

From Dev

How to get cookies from request module in node.js?

From Dev

how to remove cache from http get reqest on node js

From Dev

HTTP Request in Node Js

From Dev

Node.js: get path from the request

From Dev

Get request body from node.js's http.IncomingMessage

From Dev

undefined data using http.get() request to node.js from angular2?

From Dev

How to get followed javascripts name in HTTP request using Node.js?

From Dev

In node.js if no response is received from an http request, how do you know?

From Dev

In node.js if no response is received from an http request, how do you know?

From Java

node.js http 'get' request with query string parameters

From Dev

Send an http get request with parameters in Node.js

From Dev

Node.js HTTP Get Request to Mailchimp Returns Error

From Dev

Unable to authenticate HTTP GET Request Node.js + Expressjs

From Dev

How to get correct data from HTTP Request

From Dev

node.js forward http request from 'net' server to express

From Dev

Using the data from an HTTP request in node.js

From Dev

node.js forward http request from 'net' server to express

From Dev

Get data from GET request in node.js parameters undefined

From Dev

HTTP request callback on Node JS

From Dev

How to stop http request or stop handling http request result, when moving away from state?

From Dev

Node.js | get unique result from multiple querys

From Dev

Get result.insertId from callback function in node.js

Related Related

  1. 1

    How to get data out of a Node.js http get request

  2. 2

    How to return ArrayBuffer from $http request in Node.js?

  3. 3

    how to get the value from request.get in node js

  4. 4

    How can I get the http request headers actually sent by me in node.js http request

  5. 5

    How can I get the http request headers actually sent by me in node.js http request

  6. 6

    how to get key value from json result in node js

  7. 7

    HTTP GET request with parameters Node.js

  8. 8

    How to get cookies from request module in node.js?

  9. 9

    how to remove cache from http get reqest on node js

  10. 10

    HTTP Request in Node Js

  11. 11

    Node.js: get path from the request

  12. 12

    Get request body from node.js's http.IncomingMessage

  13. 13

    undefined data using http.get() request to node.js from angular2?

  14. 14

    How to get followed javascripts name in HTTP request using Node.js?

  15. 15

    In node.js if no response is received from an http request, how do you know?

  16. 16

    In node.js if no response is received from an http request, how do you know?

  17. 17

    node.js http 'get' request with query string parameters

  18. 18

    Send an http get request with parameters in Node.js

  19. 19

    Node.js HTTP Get Request to Mailchimp Returns Error

  20. 20

    Unable to authenticate HTTP GET Request Node.js + Expressjs

  21. 21

    How to get correct data from HTTP Request

  22. 22

    node.js forward http request from 'net' server to express

  23. 23

    Using the data from an HTTP request in node.js

  24. 24

    node.js forward http request from 'net' server to express

  25. 25

    Get data from GET request in node.js parameters undefined

  26. 26

    HTTP request callback on Node JS

  27. 27

    How to stop http request or stop handling http request result, when moving away from state?

  28. 28

    Node.js | get unique result from multiple querys

  29. 29

    Get result.insertId from callback function in node.js

HotTag

Archive