On Tuesday, February 12, 2013 9:06:22 AM UTC+7, s thapa wrote:
>
> Thanks asynqronic, 
>
> Following code,
>
> *profiles3.js*
>
> module.exports = function(callback){
>   var spawn = require('child_process').spawn,
>   ls = spawn('ls', ['-lh', '/usr']);
>
>   ls.stdout.on('data', callback);
>   ls.stderr.on('data', callback);
>   ls.on('exit', callback);
> };
>
> *index.js*
>
> exports.index = function(req, res){
>         profiles3(function(data){
>           res.writeHead(200, {
>             "Content-Type": "text/plain",
>             "Content-Length": data.length
>         });
>                 res.end(data, 'uft-8');
>         });
> };
>
>
> Giving following error, 
>
> Express server listening on port 3000
> GET / 200 15ms
>
> http.js:687
>     throw new Error('Can\'t render headers after they are sent to the 
> client.'
>           ^
> Error: Can't render headers after they are sent to the client.
>     at ServerResponse.OutgoingMessage._renderHeaders (http.js:687:11)
>     at ServerResponse.res._renderHeaders 
> (/home/sthapa/Node/stylus5/node_modules/
> express.io/node_modules/connect/lib/patch.js:69:27)
>
>  
My code is supposed to use plain Node. If you use express.io that is 
actually superset of Express.js I think you should use Express's function 
res.send(). It will set all headers automatically except Content-Type that 
should be set manually because type of your data is probably Buffer. Try 
this code:

*index.js*

exports.index = function(req, res){
        profiles3(function(data){
          res.set('Content-Type', 'text/html');
          res.send(data);
};

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to