TheUnnamed TheUnnamed - 2 years ago 106
Node.js Question

Error performing get request with Angular $resource

I am doing a function in order to do a

request to a specified route which sends a string to the backend in order to return some results based on that string, and I am getting this error:

Error: [$resource:badcfg] Error in resource configuration. Expected response to contain an array but got an object

Here is the Angular part:


<input type="text" data-ng-model="searchStr">
<textarea> {{responseData}} </textarea>


$scope.$watch('searchStr', function (tmpStr)
if (!tmpStr || tmpStr.length == 0)
return 0;

// if searchStr is still the same..
// go ahead and retrieve the data
if (tmpStr === $scope.searchStr) {
Search.get({ 'search': $scope.searchStr })
.$promise.then(function(data) {
$scope.responseData = data;


.factory('Search', function($resource) {
return $resource('/api/search/:search', {});

And this is what I have in the node part:

app.get('/api/search/:search', function(req, res, next) {
request.get('' +, function (error, response, body) {
console.log(error, response, body);

I know that in the backend everything is right because if I do a post from postman to
is the supposed string/search-term sent from the frontend to that route it is returning all of the results I need. So it seems to be something that I am doing something wrong in the frontend.

Any suggestions?

Answer Source

I think you need to specify isArray:false on your service.

return $resource('/api/search/all', {}, {
        'get' : {method : 'GET', isArray : false},
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download