[Answer]-Nodejs httpsync module – Content in server response is <SlowBuffer 64 61 74 71>?

1👍

✅

The data is coming back as a Buffer, not a string. The documentation for that can be found here. You can use data.toString() to get a more readable representation of it.

0👍

As of October 10 2014, httpsync no longer works and has been deprecated. The linked suggested library, urllib-sync, has also been archived on GitHub on April 5 2022.

I wrote sync-request-curl as a replacement which will help with sending synchronous HTTP requests.

You can install the library with the command

npm install sync-request-curl

The library contains a subset of the features in the original sync-request but leverages node-libcurl for better performance and additional libcurl options in NodeJS.

Here is a basic use case for a GET request:

// import request from 'sync-request-curl';
const request = require('sync-request-curl');
const response = request('GET', 'https://ipinfo.io/json');
console.log('Status Code:', response.statusCode);
console.log('body:', response.body.toString());

Please consult the documentation for further examples.

Specific to the code snippet in this question, it can be rewritten as:

const request = require('sync-request-curl');

function requiresDR(marker_type) {
  const url = `http://${config.adminpan.ip}:${config.adminpan.port}${config.adminpan.routes.is_marker_dr_required}`;
  const res = request('POST', url, { json: marker_type });
  console.log(res.body.toString());
}

Hope this helps someone who visited this question :).

Leave a comment