The client side code snippet:

$http({
  method: 'GET',
  url: '/admin?operation=getAdminInfo',
  data: {data: 'test'}
}).then(function(rsp){...});

The server side code snippet:

console.log('req = ' + req);
console.log('req.header = ' + JSON.stringify(req.header));
console.log('req.query = ' + JSON.stringify(req.query));
console.log('req.body = ' + JSON.stringify(req.body));
console.log('req.cookies = ' + JSON.stringify(req.cookies));
console.log('req.params = ' + JSON.stringify(req.params));
console.log('req.xhr = ' + JSON.stringify(req.xhr));

The output in the server console:

req = [object Object]
req.header = undefined
req.query = {"operation":"getAdminInfo"}
req.body = {}
req.cookies = {"token":"eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJzeXN0ZW0iLCJpc3MiOiJodHRwczovL3d3dy5uZXRhb3RlYy5jb20iLCJpYXQiOjE1MTYwNjM1Njk1MDQsInVzZXJfcm9sZSI6MSwidXNlcm5hbWUiOiJzeXN0ZW0iLCJleHAiOjE1MTYwNjM1NzY3MDR9.K2Rh4WTNtkhP2gxWLnGW7846zMKaW-WKEF2hykJmvn3zNmGyIDprrnswzqqrpmAvNTP8gylnCn3b7K_gRJ-WOif7MnQYiG4mu8fNGW-hCUQeTyqzUgsP9sIXzm_A3pWFlW8eL88Dydugf9JhhDeB18QUJV-i4zT6bCfE3stY1QXJZzNsKd8HRl22n78XCb5XRxdiEnmhqF6sNb9h40jKzcd6Ny0KX6uEe1SE54OYbp_BcR4Lr69C6tcFNgwtiJusFEymnMcbkqSst_GUztiObPeYZIwrfEUMEobUsxvx0v2zUQp9EJDF-MyaGid5kJwyv_ittFFKRChBSllI3luNXA"}
req.params = {}
req.xhr = false

How can I extract/get the data {data: 'test'} at node.js? AngularJS version is 1.6.6; Node.js version is v8.1.4; app.js at node.js: enter link description here

share|improve this question
    
@Sajeetharan, no, no. you take a look at my output, I cannot get the data at node.js. at angularjs side I'm following the instruction of angularjs document strictly. In the document it shows data – {string|Object} – Data to be sent as the request message data. – Oops Jan 16 at 17:39
1  
which is same! you need to strigify the data if you are sending it as ajson, also use http.post with angularjs – Sajeetharan Jan 16 at 17:41
    
I changed the config to data: JSON.stringify({data: 'test'}) and get the same result. Also, at the angularjs document, there is an example using code data: { test: 'test' }. – Oops Jan 16 at 17:44
    
bro check the duplicate marked question, you need to check the headers as well – Sajeetharan Jan 16 at 17:45
    
Change the config method: 'GET' to method: 'POST' get the result in req.body. Thank you. But this is not duplicate with the thread you mentioned -- JSON.stringify does not help here. – Oops Jan 16 at 17:47
up vote 1 down vote accepted

Change the method from Get to Post, since you are sending an object to the server.

$http({
  method: 'POST',
  url: '/admin?operation=getAdminInfo',
  data: {data: 'test'}
}).then(function(rsp){...});
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.