Not able to get the value from node.js backend back to my $http angular ajax call success block.when alerted the value of data it is empty

When posting data from angular passing the data to nodejs server and data is getting successfully inserted in mongodb.

data is requested from angular using $http call to the node.js server but the node.js server inspite of successful fetching of data from database is unable to send the data to the angular js controller.Does res.send(str) mentioned below send back the response with the content to the controller?

In the response used for node.js used str is the data fetched from the mongodb successfully res.end(str);

In the controller I used

$http.get(url).success(function(data) {

I am not receiving any value for data and it is returning and going to the error block rather than success.

angularjscontroller:

 $scope.list = function() {
  var url = 'http://192.168.0.104:1212/getangularusers';    
  $http.get(url).success(function(data) {
    $scope.users = data;
  }).
    error(function(data){
     alert('moving into error block');
   });
 };

 $scope.list();
 }

appmongodbangulr.js(node.js server)

app.get('/getangularusers', function (req, res) {
res.header("Access-Control-Allow-Origin", "http://localhost");
res.header("Access-Control-Allow-Methods", "GET, POST");
db.things.find('', function(err, users) {
 if( err || !users) console.log("No users found");
   else 
{
     res.writeHead(200, {'Content-Type': 'application/json'});
    str='[';
    users.forEach( function(user) {
        str = str + '{ "name" : "' + user.username + '"},' +'\n';
     });
    str = str.trim();
    str = str.substring(0,str.length-1);
    str = str + ']';
     res.end( str);
}
});
});
app.listen(1212);

Please provide me with the solution how to pass the data that is fetched back to the controller?

You should NOT create JSON manually in any case. You need to use JSON.stringify method.

From the other hand, if you need to convert array of objects into array of other objects, then you definitely need to use map method.

As the result you can see something like the following:

res.writeHead(200, {'Content-Type': 'application/json'});
var usersNames = users.map(function(user){
    return user.username;
});
res.end(JSON.stringify(usersNames));

P.S. don't use global scope for names, as you do with str variable.