Getting an Array with Angular 2 from mongoose mongoDB database

342
April 20, 2017, at 9:38 PM

I am trying to retrieve my Members collection in my angular 2 front end.

in my routes I have:

router.post('/memberprofile', function (req, res) {
Member.find({}, function (err, members){
    if (err){
    console.log(err);
}else{
  res.json(members);
  console.log('retrieved members', members.length);
  console.log(members);
}
});
});

I am attempting to GET it by using this code:

export class MemberprofileComponent implements OnInit {
  member:Object;
  members:Array<Object>;
  result:Array<Object>;
  constructor(
private authService:AuthService,
private router:Router,
private http:Http
 ) {

this.http.get('http://localhost:3000/users/memberprofile')
              .subscribe(result => this.result = result.json());
              console.log(this.result);
               }

I am then given the following error in the console:

SyntaxError: Unexpected token < in JSON at position 0

Screenshot of Network Tab

Screenshot of Response

My question is, how am I able to push the array to the front end, I hope to eventually place the result into a table but at the moment if anyone can work out why I cant console log this array that would be great.

Thanks!

READ ALSO
Mongoose - mapping json object to Schema

Mongoose - mapping json object to Schema

I'm trying to learn mongo/mongoose and am importing json into mongodb

377
Hapijs Forwarding a stream to another server

Hapijs Forwarding a stream to another server

I try to upload a image to my Hapijs Server via stream and send(pipe) the data to another Hapijs instance

404
File downloaded by curl but not by node.js

File downloaded by curl but not by node.js

So I'm trying to download a file through nodejs that opens fine in the browser, and even downloads fine in tools like curlBut nodejs just fails for some reason to download the file

850
Lambda exits before completing, but works locally

Lambda exits before completing, but works locally

I'm writing a simple Lambda function for a data processing pipeline, which gets called by Kinesis FirehoseThis function downloads images from a URL, uploads them to S3, checks whether they have a face in them using OpenCV, and if they do, loads the image into Rekognition

264