Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8396467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:32:36+00:00 2026-06-09T20:32:36+00:00

I am writing a library which may set headers. I want to give a

  • 0

I am writing a library which may set headers. I want to give a custom error message if headers have already been sent, instead of just letting it fail with the "Can’t set headers after they are sent" message given by Node.js. So how to check if headers have already been sent?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:32:38+00:00Added an answer on June 9, 2026 at 8:32 pm

    EDIT: as of express 4.x, you need to use res.headersSent. Note also that you may want to use setTimeout before checking, as it isn’t set to true immediately following a call to res.send(). Source

    Simple: Connect’s Response class provides a public property “headerSent”.

    res.headerSent is a boolean value that indicates whether the headers have already been sent to the client.

    From the source code:

    /**
       * Provide a public "header sent" flag
       * until node does.
       *
       * @return {Boolean}
       * @api public
       */
    
      res.__defineGetter__('headerSent', function(){
        return this._header;
      });
    

    https://github.com/senchalabs/connect/blob/master/lib/patch.js#L22

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a library which is a set of classes meant to be
I have been writing a library for my project (for now I am using
I have been mulling over writing a peak-fitting library for a while. I know
I have a library that I'm writing which processes keystroke events using the Win32
I am writing a library in VB.NET in which I have added, among others,
I am writing a library which uses a few functions from the windows user32.dll
I am writing a C library which involves telling other computers on the subnet
I am writing a utility in Java that reads a stream which may contain
I am writing a library in standard C++ which does the phonetic conversion. I
I am writing a library of utility classes, many of which are singletons. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.