buenas noches, estoy empezando a tabajar con node.js ... cuando ejecuto mi codigo en el navegador me arroja este error:
Error: Can't set headers after they are sent.
at ServerResponse.OutgoingMessage.setHeader (http.js:689:11)
at ServerResponse.header (/var/www/node/node_modules/express/lib/response.js:666:10)
at ServerResponse.send (/var/www/node/node_modules/express/lib/response.js:146:12)
at /var/www/node/server.js:21:7
at Array.forEach (native)
at /var/www/node/server.js:20:12
at Layer.handle [as handle_request] (/var/www/node/node_modules/express/lib/router/layer.js:82:5)
at next (/var/www/node/node_modules/express/lib/router/route.js:100:13)
at Route.dispatch (/var/www/node/node_modules/express/lib/router/route.js:81:3)
at Layer.handle [as handle_request] (/var/www/node/node_modules/express/lib/router/layer.js:82:5)
el codigo que estoy trabajando es:
var express = require('express');
var server = express();
var messages = [];
var responses = [];
server.get('/',function(req,res){
res.send('hello world');
});
server.get('/messages',function(req,res){
responses.push(res);
// res.send(messages+ '<script>setTimeout(function(){window.location.rel oad()}, 1000)</script>');
});
server.get('/messages/:message',function(req,res){
messages.push(req.params.message);
responses.forEach(function(res){
res.send(messages+'<script>window.location.reload( )</script>');
});
res.send('tu mensaje es '+req.params.message);
});
server.listen(3000);
alguien sabe porque me aparece ese error??? gracias