I was trying to send data from Drupal page to node
Drupal code
function sample_submit($form, &$form_state) { //Function to connect with node and save into Mongo using node
$jsonData = check_plain($form_state['values']['jsonData']);
$request_url = "http://10.20.5.112:3000/save";
$options = array(
'method' => 'POST',
'data' => $jsonData,
'timeout' => 15,
'headers' => array('Content-Type' => 'application/x-www-form-urlencoded'),
);
$result = drupal_http_request($request_url, $options);
}
Node.Js
app.post('/save', function(req, res){ //Rest Api Function to get data from pushed by drupal
//console.log(req.data);
res.send('Success');
});
How to get the data send from drupal as jsondata in the node.js
You can get the posted data from req.body, for example console.log(req.body);
http://expressjs.com/api.html#req.body
or you can use req.param, for example console.log(req.param('data'));
http://expressjs.com/api.html#req.param