Must res.end() be called in express with node.js?

I have several Express applications, and I see that in some modules, res.end() is called at the end of a request handler (after res.send or res.json), while in others, it isn't called.

For example:

app.get('/test', function(req, res) { res.send('Test', 200); });


app.get('/test', function(req, res) { res.send('Test', 200); res.end(); });

Both cases work, but I'm afraid about leaks or running out file descriptors or something like that, when I run many requests. Which one is "more correct"?

-------------Problems Reply------------

The answer to your question is no. You don't have to call res.end() if you call res.send(). res.send() calls res.end() for you.

Taken from /lib/response.js, here is the end of the res.send() function:

//. . .
// respond
this.end(head ? null : body);
return this;

Category:node.js Views:0 Time:2013-12-03

Related post

  • Express.js, Node.js Jade - Following the tutorials, and getting errors 2011-05-01

    Well I'm trying to get into Node.js / Express.js - however I've been having a few issue going through the screencast, the first issue, now resolved, was pretty obvious when it was spotted (Express.js, Node.js Jade vim). However, I'm now getting the f

  • Is there anyway Express in Node.js can have more than one static folder? 2011-08-09

    I'm working on a project where there is a user uploaded collection of styles, scripts and images and then their is my app's collection of styles, scripts and images. They're two different places on my server. Is there anyway I can setup Express in No

  • Learning Express for Node.js 2011-11-15

    Anyone have pointers to good resources for learning Express? I'm aware of the documentation and the videos. Curious if there are any other good resources out there. --------------Solutions------------- If I would do it all over again wit

  • How is req and res accessible accross modules in Express.js 2011-04-18

    While using express.js for handling various routes I want to encapsulate all of my route code in a seperate module, but how can I access the req and res object across modules, See the code below The main file examples.js is written as follows var app

  • Pass String along a res.redirect(path) call in Express Node project 2012-03-11

    I am using res.redirect('/') after a save operation in an Express project How can I pass a certain string along with the redirect? I want to pass along some sort of notice to be displayed when the view is rendered. Many of my save/delete operations l

  • How to I load a javascript file using express and node.js? 2010-10-22

    I'm trying to figure out how to load a simple javascript client-side library while using node.js and express. Any ideas? See below. HAML: %script{type: 'text/javascript', src: '/jquery-1.4.3.js'} %script{type: 'text/javascript', src: '/client.js'} ap

  • Does express for node.js have a .request() 2011-04-07

    I'm trying to get a response from an outside url using the below code, but im having no luck. Can someone shed some light on what I'm doing wrong and give any pointers they think could be helpful. var express = require('express'), require('events');

  • Express.js, Node.js Jade vim 2011-04-30

    Help, before I throw my beautiful, expensive MacBook Pro to the ground in a fit of annoyance. I'm trying to get something working in Expressjs, and it's really getting on my nerves. I'm following the tutorial on: Screen

  • How can I use a slug with Express and Node.js? 2011-12-20

    How can I go from: http://url:port/user?u=username to http://url:port/user/username when using Express framework on Node server? Current JavaScript server side code: app.get('/user', function(req, res){ var username = req.param("u"); users.findOne({u

Copyright (C), All Rights Reserved.

processed in 0.106 (s). 11 q(s)