0

How do you troubleshoot this *?

I'm sorry but it is SO disappointing when what should be simple things don't work the way it is claimed that they should.

Following is clipped directly from the projetc's gitHub site.

And if I do the same thing in PostMan - no problem.

The first console.log() works. But NONE of the following get called. It appears the the .then()s nor the .fail()s get called. And if I add a catch() that too isn't called.

I DO have requestify working in different node.js Express web applications without issue. This application is a node.js console application (a single .js file) which exists in the root of the Express web app.

This .js file doesn't throw any errors when compiled or executed.

console.log("Let's begin");

/* appears to  do nothing */
requestify.get('https://www.example.com/api/get.json')
.then(function (response) {
    console.log('response', response.getBody());
})
.fail(function (response) {
        console.log('response Error', response.getCode());
    })
;


/* also appears to do nothing */
requestify.request('https://www.example.com/api/get.json', {
    method: 'GET'
})
.then(function(response) {
    console.log('responsebody', response.getBody());
    console.log('response headers',response.getHeaders());
    console.log('responseheader Accept', response.getHeader('Accept'));
    console.log('response code', response.getCode());
    console.log('responsebody RAW', response.body);
    })
.fail(function (response) {
        console.log('response Error', response.getCode());
    })
;
Steve
  • 905
  • 1
  • 8
  • 32
  • Did you require the module? `var requestify = require('requestify'); ` – Badacadabra Apr 15 '17 at 13:39
  • There are no errors when compiled or run-time. If i didn't the error "`requestify` not defined" would occur. But yes. Thanks for asking. – Steve Apr 15 '17 at 13:41
  • I have tested your code and it is working perfectly fine. You just have a typo in your first `console.log`. Please use double quotes ("") and test again. – Badacadabra Apr 15 '17 at 13:48
  • You are right. I see that typo now. I removed the line entirely and still the same issue. Are you doing this in a console. app or a web app? Show your code? – Steve Apr 15 '17 at 13:52
  • I copy/pasted your code in a file, then I ran `node file.js`... Pretty simple. xD – Badacadabra Apr 15 '17 at 13:55
  • Now I am thinking about it... I just added `var requestify = require('requestify');` at the top of the file as suggested above. – Badacadabra Apr 15 '17 at 13:57
  • You must have dropped your file.js into some prebuilt project. Otherwise you would not have had the necessary nmp install & dependencies. I wonder if your install packages have something in them I don't. Or maybe a difference in version or a global package. mmmmm – Steve Apr 15 '17 at 13:59
  • You got me thinking. I could run this in an adjacent web app instead of the console app. I'm trying to work with that right now. – Steve Apr 15 '17 at 14:03
  • Well... Of course, I also ran `npm i requestify` in a test directory, but do I have to mention this? – Badacadabra Apr 15 '17 at 14:03
  • @Badacadabra Thanks brother. It has to be something to do with trying to do with web requests from a console app. I just migrated it to a web app and it worked the first try. – Steve Apr 15 '17 at 14:21
  • @user2367083 the snippet is pretty basic it should be working you are clearly missing something, like dependencies. – Gntem Apr 15 '17 at 14:23
  • @Mr.Phoenix I think youre right. But the dependencies r'tify requires are all internal to r'tify requiring them. I don't write require() statements to bring in modules that r'tify depends. r'tify would never recognize it even if I did. And per the r'tify docs all dependencies exists (jquery, q, underscore). Maybe version issue? Couldn't find it. Any other dependencies I should require? I've no idea which. At any rate it ran the first try as a web app but not at all as a console app; even though the console .js file is in the root of web app that is calling my console app's .js file. thx – Steve Apr 15 '17 at 14:33

2 Answers2

0

2 things,

  1. You didn't require requestify,
  2. You have 3 single quotes in your first console log. So that's sure to break;.

'use strict';

const requestify = require('requestify');

/* appears to  do nothing */
requestify.get('https://www.example.com/api/get.json')
  .then(function (response) {
    console.log('response', response.getBody());
  })
  .fail(function (response) {
    console.log('response Error', response.getCode());
  })
;


/* also appears to do nothing */
requestify.request('https://www.example.com/api/get.json', {
  method: 'GET'
})
  .then(function(response) {
    console.log('responsebody', response.getBody());
    console.log('response headers',response.getHeaders());
    console.log('responseheader Accept', response.getHeader('Accept'));
    console.log('response code', response.getCode());
    console.log('responsebody RAW', response.body);
  })
  .fail(function (response) {
    console.log('response Error', response.getCode());
  })
;
  • My including that console.log() in the OP was the typo. My actual project has a different message in the .log(). And I do require() as necessary. If either of these suggestions are the issue the code couldn't possible compile without error. – Steve Apr 15 '17 at 13:57
0

I can't say exactly what it is but requestify isn't working a console app. But is working on the first try having migrated to a webapp.

Steve
  • 905
  • 1
  • 8
  • 32