node js sync request code not working

Viewed 1528

Please help me with the following code where I am trying to make a synchronous get request in app.js and I want this method to be exposed to another file called index.js

Code for app.js

var qnamod = function(query) {
    var request = require('sync-request');
    var querystring = require('querystring').escape(query);
    var resqna = request('GET', 'http://<host>/_analyse?question='+ querystring);
    //console.log(res.getBody());
    var qna = JSON.parse(resqna.getBody('utf8'));
}
exports.qnamod = qnamod;

Code for index.js

   var counting = require('./app.js');
   var resp = counting.qnamod("Forgot password");
   console.log(resp);

On executing index.js I get the following error: INFO: Could not find files for the given pattern(s). Could not use "nc", falling back to slower node.js method for sync requests. undefined

1 Answers

From sync-request's README, it says this.

Could not use "nc", falling back to slower node.js method for sync requests. If you are running on windows, or some unix systems, you may see the message above. It will not cause any problems, but will add an overhead of ~100ms to each request you make. If you want to speed up you requests, you will need to install an implementation of the nc unix utility. This usually done via something like: apt-get install netcat

So the truth is that it isn't a huge error, it will just slow your request down. BUT REMEMBER, this library is NOT intended for Production use. It is a bad paradigm which will block your thread.

Related