when running the route the node sends me this message: Error: Can not set headers after they are sent

2

When accessing the route you specify, the files that I have in the public folder are not loaded, only some are loaded and in the nodejs console you send me the following message:

Error: Can't set headers after they are sent.
    at SendStream.headersAlreadySent (C:\api-rest\node_modules\send\index.js:402:13)
    at SendStream.send (C:\api-rest\node_modules\send\index.js:625:10)
    at onstat (C:\api-rest\node_modules\send\index.js:737:10)
    at FSReqWrap.oncomplete (fs.js:123:15)
Error: Can't set headers after they are sent.
    at SendStream.headersAlreadySent (C:\api-rest\node_modules\send\index.js:402:13)

My code is as follows:

app.get('/', (req, res, err) => {

Noticias.find({}, (e, noticias) => {
    noticias.forEach(function (element) {
        var myStrin = '' + element.Contenido;
        myStrin = myStrin.slice(0, 100);
        element.Contenido = myStrin + '...';
    }, this);
    if (e) {
        console.log(e);
    } else if (!noticias) {
        console.log("Error, el archivo no existe")
    } else {
        res.render('index', { noticias, title: "ICMA", uno: "select", dos: "", tres: "", cuatro: "", cinco: "" })
    }
   }) 
});
    
asked by Martínez Oscar 29.05.2017 в 00:24
source

1 answer

0

The error refers to trying to respond twice to the http request.

Can you upload the code implemented in this function? News.find () to discard that there you are sending an additional response to the one you have in res.render ().

    
answered by 08.06.2017 в 17:11