Hi ajlopez, thanks for your response and attention to my problem.
The piece of code (i.e., write header) is in the router.js file. I am
sorry for not providing enough information about the environment in which I
am working. I am working under a rather big project. According to the
package.json file of the project, I see that under "dependencies":
"express" : ">=3.4.0"
It was about one and half months ago when I did npm install of the
project. The Express 4 was not available at the time.
On Thursday, April 17, 2014 1:28:19 PM UTC-4, JPJen wrote:
>
>
> I am using Node.js.
>
> I have a piece of code that works well in returning the expected response
> and the response is received quickly:
>
> if (req.accepts('json')) {
>
> res.header('Content-Type', 'application/json');
>
> res.send(res.locals.items, 200);
>
> }
>
>
> In addition to the Status 200, I want to add a message in the header.
> Therefore, I modified the code above a little bit to be consistent with the
> syntax, which is, *response.writeHead(statusCode, [reasonPhrase],
> [headers])*, stated in the Node.js v0.10.26 Manual & Documentation (
> http://nodejs.org/api/http.html):
>
> if (req.accepts('json')) {
>
> res.writeHead( 200, 'my_customizd_message', {'Content-Type' :
> 'application/json'} );
>
> res.send(res.locals.items);
>
> }
>
> then, I got an error in the console saying "Error : can't set headers
> after they are sent".
>
> I tried something else:
>
> if (req.accepts('json')) {
>
> res.writeHead( 200, 'my_customizd_message', {'Content-Type' :
> 'application/json'} );
>
> res.end();
>
> }
>
> There is no error message on the console. But, nothing is returned. The
> code is running forever. I am hoping someone could help me out. Thank you
> very much.
>
>
>
--
--
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/d/optout.