Process crashed with: TypeError: callback is not a function












0















I am trying to call this function that has an HTTP post request so that I can get the body in different parts of the bigger script



Below is the code:



var request = require('request')
var myJSON = require("JSON");

function getJSON ( input, callback){
var all = {
'documents': [
{
'id': '1',
// Change this text to test
'text': 'not helpful'
}
]
};
request({
headers: {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key' :'0df563b09d8b42b095dd32158e4afd13',
'Host' : 'westus.api.cognitive.microsoft.com'
},
uri: 'https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment',
json: true,

body: all,
method: 'POST'
}, function (error, response, body) {

if (error || response.statusCode !== 200) {
callback(error || {statusCode: response.statusCode});
}
else
callback(body);
return callback;
});
}

body = getJSON("test");









share|improve this question























  • ---------------------- This is the error im getting: Process crashed with: TypeError: callback is not a function at Request._callback (evalmachine.<anonymous>:30:5)

    – Reina Baba
    Nov 25 '18 at 10:59
















0















I am trying to call this function that has an HTTP post request so that I can get the body in different parts of the bigger script



Below is the code:



var request = require('request')
var myJSON = require("JSON");

function getJSON ( input, callback){
var all = {
'documents': [
{
'id': '1',
// Change this text to test
'text': 'not helpful'
}
]
};
request({
headers: {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key' :'0df563b09d8b42b095dd32158e4afd13',
'Host' : 'westus.api.cognitive.microsoft.com'
},
uri: 'https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment',
json: true,

body: all,
method: 'POST'
}, function (error, response, body) {

if (error || response.statusCode !== 200) {
callback(error || {statusCode: response.statusCode});
}
else
callback(body);
return callback;
});
}

body = getJSON("test");









share|improve this question























  • ---------------------- This is the error im getting: Process crashed with: TypeError: callback is not a function at Request._callback (evalmachine.<anonymous>:30:5)

    – Reina Baba
    Nov 25 '18 at 10:59














0












0








0








I am trying to call this function that has an HTTP post request so that I can get the body in different parts of the bigger script



Below is the code:



var request = require('request')
var myJSON = require("JSON");

function getJSON ( input, callback){
var all = {
'documents': [
{
'id': '1',
// Change this text to test
'text': 'not helpful'
}
]
};
request({
headers: {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key' :'0df563b09d8b42b095dd32158e4afd13',
'Host' : 'westus.api.cognitive.microsoft.com'
},
uri: 'https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment',
json: true,

body: all,
method: 'POST'
}, function (error, response, body) {

if (error || response.statusCode !== 200) {
callback(error || {statusCode: response.statusCode});
}
else
callback(body);
return callback;
});
}

body = getJSON("test");









share|improve this question














I am trying to call this function that has an HTTP post request so that I can get the body in different parts of the bigger script



Below is the code:



var request = require('request')
var myJSON = require("JSON");

function getJSON ( input, callback){
var all = {
'documents': [
{
'id': '1',
// Change this text to test
'text': 'not helpful'
}
]
};
request({
headers: {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key' :'0df563b09d8b42b095dd32158e4afd13',
'Host' : 'westus.api.cognitive.microsoft.com'
},
uri: 'https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment',
json: true,

body: all,
method: 'POST'
}, function (error, response, body) {

if (error || response.statusCode !== 200) {
callback(error || {statusCode: response.statusCode});
}
else
callback(body);
return callback;
});
}

body = getJSON("test");






node.js http post callback request






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 25 '18 at 10:58









Reina BabaReina Baba

91




91













  • ---------------------- This is the error im getting: Process crashed with: TypeError: callback is not a function at Request._callback (evalmachine.<anonymous>:30:5)

    – Reina Baba
    Nov 25 '18 at 10:59



















  • ---------------------- This is the error im getting: Process crashed with: TypeError: callback is not a function at Request._callback (evalmachine.<anonymous>:30:5)

    – Reina Baba
    Nov 25 '18 at 10:59

















---------------------- This is the error im getting: Process crashed with: TypeError: callback is not a function at Request._callback (evalmachine.<anonymous>:30:5)

– Reina Baba
Nov 25 '18 at 10:59





---------------------- This is the error im getting: Process crashed with: TypeError: callback is not a function at Request._callback (evalmachine.<anonymous>:30:5)

– Reina Baba
Nov 25 '18 at 10:59












1 Answer
1






active

oldest

votes


















0














In your code snippet, when you called your function getJSON, you did not provide a callback parameter.



body = getJSON("test"); // <--- Missing parameter


Meaning, getJSON("test") is missing a callback parameter.
I.E.
getJSON("test", function(){console.log("Do something")});



This probably leads to the callback parameter to be undefined.






share|improve this answer
























  • Thank you so much!! But now that I want to pass the body of the request to the full script how do I do it? instead of var answer = getJSON("test", function(){console.log("Do something")}); I want to store the body of the response in answer. Thanks!

    – Reina Baba
    Nov 25 '18 at 12:13













  • Reina Baba - What you wanted to do cannot be done in your code. You are only getting the body of the response as part of the promise returned from making the POST request. You cannot pass the request body when calling the function getJSON since you do not have it yet. I would break apart the method to return the body of the response and then run any logic you need on it. If my answer helped you, consider marking it as an answer.

    – tomerpacific
    Nov 25 '18 at 13:13











  • @ReinaBaba - Did you manage to sort things out?

    – tomerpacific
    Dec 10 '18 at 16:23











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466780%2fprocess-crashed-with-typeerror-callback-is-not-a-function%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














In your code snippet, when you called your function getJSON, you did not provide a callback parameter.



body = getJSON("test"); // <--- Missing parameter


Meaning, getJSON("test") is missing a callback parameter.
I.E.
getJSON("test", function(){console.log("Do something")});



This probably leads to the callback parameter to be undefined.






share|improve this answer
























  • Thank you so much!! But now that I want to pass the body of the request to the full script how do I do it? instead of var answer = getJSON("test", function(){console.log("Do something")}); I want to store the body of the response in answer. Thanks!

    – Reina Baba
    Nov 25 '18 at 12:13













  • Reina Baba - What you wanted to do cannot be done in your code. You are only getting the body of the response as part of the promise returned from making the POST request. You cannot pass the request body when calling the function getJSON since you do not have it yet. I would break apart the method to return the body of the response and then run any logic you need on it. If my answer helped you, consider marking it as an answer.

    – tomerpacific
    Nov 25 '18 at 13:13











  • @ReinaBaba - Did you manage to sort things out?

    – tomerpacific
    Dec 10 '18 at 16:23
















0














In your code snippet, when you called your function getJSON, you did not provide a callback parameter.



body = getJSON("test"); // <--- Missing parameter


Meaning, getJSON("test") is missing a callback parameter.
I.E.
getJSON("test", function(){console.log("Do something")});



This probably leads to the callback parameter to be undefined.






share|improve this answer
























  • Thank you so much!! But now that I want to pass the body of the request to the full script how do I do it? instead of var answer = getJSON("test", function(){console.log("Do something")}); I want to store the body of the response in answer. Thanks!

    – Reina Baba
    Nov 25 '18 at 12:13













  • Reina Baba - What you wanted to do cannot be done in your code. You are only getting the body of the response as part of the promise returned from making the POST request. You cannot pass the request body when calling the function getJSON since you do not have it yet. I would break apart the method to return the body of the response and then run any logic you need on it. If my answer helped you, consider marking it as an answer.

    – tomerpacific
    Nov 25 '18 at 13:13











  • @ReinaBaba - Did you manage to sort things out?

    – tomerpacific
    Dec 10 '18 at 16:23














0












0








0







In your code snippet, when you called your function getJSON, you did not provide a callback parameter.



body = getJSON("test"); // <--- Missing parameter


Meaning, getJSON("test") is missing a callback parameter.
I.E.
getJSON("test", function(){console.log("Do something")});



This probably leads to the callback parameter to be undefined.






share|improve this answer













In your code snippet, when you called your function getJSON, you did not provide a callback parameter.



body = getJSON("test"); // <--- Missing parameter


Meaning, getJSON("test") is missing a callback parameter.
I.E.
getJSON("test", function(){console.log("Do something")});



This probably leads to the callback parameter to be undefined.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 25 '18 at 11:05









tomerpacifictomerpacific

1,062724




1,062724













  • Thank you so much!! But now that I want to pass the body of the request to the full script how do I do it? instead of var answer = getJSON("test", function(){console.log("Do something")}); I want to store the body of the response in answer. Thanks!

    – Reina Baba
    Nov 25 '18 at 12:13













  • Reina Baba - What you wanted to do cannot be done in your code. You are only getting the body of the response as part of the promise returned from making the POST request. You cannot pass the request body when calling the function getJSON since you do not have it yet. I would break apart the method to return the body of the response and then run any logic you need on it. If my answer helped you, consider marking it as an answer.

    – tomerpacific
    Nov 25 '18 at 13:13











  • @ReinaBaba - Did you manage to sort things out?

    – tomerpacific
    Dec 10 '18 at 16:23



















  • Thank you so much!! But now that I want to pass the body of the request to the full script how do I do it? instead of var answer = getJSON("test", function(){console.log("Do something")}); I want to store the body of the response in answer. Thanks!

    – Reina Baba
    Nov 25 '18 at 12:13













  • Reina Baba - What you wanted to do cannot be done in your code. You are only getting the body of the response as part of the promise returned from making the POST request. You cannot pass the request body when calling the function getJSON since you do not have it yet. I would break apart the method to return the body of the response and then run any logic you need on it. If my answer helped you, consider marking it as an answer.

    – tomerpacific
    Nov 25 '18 at 13:13











  • @ReinaBaba - Did you manage to sort things out?

    – tomerpacific
    Dec 10 '18 at 16:23

















Thank you so much!! But now that I want to pass the body of the request to the full script how do I do it? instead of var answer = getJSON("test", function(){console.log("Do something")}); I want to store the body of the response in answer. Thanks!

– Reina Baba
Nov 25 '18 at 12:13







Thank you so much!! But now that I want to pass the body of the request to the full script how do I do it? instead of var answer = getJSON("test", function(){console.log("Do something")}); I want to store the body of the response in answer. Thanks!

– Reina Baba
Nov 25 '18 at 12:13















Reina Baba - What you wanted to do cannot be done in your code. You are only getting the body of the response as part of the promise returned from making the POST request. You cannot pass the request body when calling the function getJSON since you do not have it yet. I would break apart the method to return the body of the response and then run any logic you need on it. If my answer helped you, consider marking it as an answer.

– tomerpacific
Nov 25 '18 at 13:13





Reina Baba - What you wanted to do cannot be done in your code. You are only getting the body of the response as part of the promise returned from making the POST request. You cannot pass the request body when calling the function getJSON since you do not have it yet. I would break apart the method to return the body of the response and then run any logic you need on it. If my answer helped you, consider marking it as an answer.

– tomerpacific
Nov 25 '18 at 13:13













@ReinaBaba - Did you manage to sort things out?

– tomerpacific
Dec 10 '18 at 16:23





@ReinaBaba - Did you manage to sort things out?

– tomerpacific
Dec 10 '18 at 16:23




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466780%2fprocess-crashed-with-typeerror-callback-is-not-a-function%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

To store a contact into the json file from server.js file using a class in NodeJS

Redirect URL with Chrome Remote Debugging Android Devices

Dieringhausen