DEV Community

Discussion on: Building a CRUD API with Node.js and MongoDB

Collapse
 
hdocampo profile image
hugol • Edited

Hi Aveesh, I am starting a new thread in order to post some error that I can not resolve by myself, maybe you can help me =)

The POST create functionality is working great, but when I trying to get all items, I am getting this error. Weird thing is that I am getting the list properly but on res.json(items) it says that "Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client"

Find the code I am using in this image =>
Code Get List

EDIT: this is the postman code, sorry I have forgotten to add it

GET /api/products HTTP/1.1
Host: localhost:8000
Content-Type: application/json
cache-control: no-cache
Postman-Token: b36b3eee-3c97-4ad6-91ee-f20743626503

Thanks in advance

Collapse
 
hdocampo profile image
hugol

Ok, solved, I find that in line 6 of my code, I left some wrong stuff in the if statement XD

instead of
if (err, products) {

it should be
if (err) {

my apologies!

Collapse
 
avneesh0612 profile image
Avneesh Agarwal

Ah np