I am trying to send some JSON data from a node js app to another web service written in Flask. I am trying to use the request library and looked at the questions here and here.
Based on the examples I came up with the following simple app. The app sends the JSON data to my flask server, but does not get/fire the callback. I have checked that the Flask application returns some data via postman and it works fine. Where am I going wrong?
[this my entire app.js]
var express = require("express");
var request = require('request');
var app = express();
app.set('view engine', 'pug');
app.get('/', function(req, res) {
console.log("here...")
request({
url: 'http://localhost:5000/receive_user_response',
method: "POST",
headers: {
"content-type": "application/json"
},
json: { // <--- I have also tried calling this as "body"
user_id: "some id...",
user_info: "some info..."
},
function(err, res, data) {
console.log('err', err) // <---- never prints any thing from here!
console.log('res', res)
console.log('data', data)
if (!err && res.statusCode == 200) {
console.log(data);
}
}
})
console.log("here...done..")
});
var server = app.listen(3000, function() {
console.log("Listening on port %s...", server.address().port);
});