1

When I make the GET request, I console.log(response) and it get a 404

  Http failure response for http://localhost:3000/api/watchings/?watchItemUniqueKey=5dab6083b68bd049c0b8f9ce%7C5daf5e0c8d261e5364acd8b6: 404 Not Found", err

So I know the value is being passed as a parameter, but my app.js file isn't seeing it. Also the console.log("output: " + req.params.test); at the beginning of the app.get isn't outputting so the GET request from watch-list.service.ts isn't hitting app.js file. Any help is appreciated. I just starting learning nodejs a month ago so still working through how things work.

watch-list.service.ts

 getWatchList(watchingId) {

    watchingId = watchingId.trim();
    let params1 = new HttpParams().set('watchItemUniqueKey', watchingId);

    return this.http.get<{}>(
        'http://localhost:3000/api/watchings/', {params: params1}
      ).
    subscribe((response) => {
        console.log(response);

      });
  }

app.js

app.get("/api/watchings/:test", (req, res, next) => {
console.log("output: " + req.params.test);
  Watching.find({"value": req.params.test})
  .then(documents =>{
  res.status(200).json({
    message: "Posts fetched Successfully",
    watchItems: documents,
  });

});
});
Andy
  • 185
  • 2
  • 6
  • 22

1 Answers1

2

What you are passing is query parameter and you should be able to access it as below :

app.get("/api/watchings", (req, res, next) => {
console.log("output: " + req.query.watchItemUniqueKey);
  Watching.find({"value": req.query.watchItemUniqueKey})
  .then(documents =>{
  res.status(200).json({
    message: "Posts fetched Successfully",
    watchItems: documents,
  });

});
});
Sandeep Patel
  • 4,815
  • 3
  • 21
  • 37