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 7081205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:53:27+00:00 2026-05-28T06:53:27+00:00

I want to be able to send a friendly error message to my user

  • 0

I want to be able to send a friendly error message to my user whenever I cannot connect to my MongoDB server from inside node.js, instead of just having node.js freaking out as it does right now.

Apparently this won’t work as I cannot access the response variable from outside a route method (app.get('/' ...), so what should I do instead?
No need to display something fancy, but just informing the user about a temporary problem would be amazing.

mongoose.connect('mongodb://localhost/test', function(err) {
    if (err) {
        //response.send('Temporary problem', 500); 
    }
});

// Routes
app.get('/', index.index);
//... And so on
  • 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-05-28T06:53:27+00:00Added an answer on May 28, 2026 at 6:53 am

    You could use alternative routes if connection error occured, so it won’t be neccessary to perfom connection checks in every request handler.

    function connect() {
      mongoose.connect(connStr, function(err) {
        if (err) {
          // all GET requests will end with error message
          app.get('*', function(req, res) {
            res.end('DB error');
          });
    
          // handle errors, retry connection attempt or something...
    
          app.listen(...);
          return;
        }
    
        // Routes
        app.get('/', index.index);
        //... And so on
    
        app.listen(...);
      };
    }
    
    var app = express.createServer();
    connect();
    

    You should however find a way to drop route '*' when your connection will be up.

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

Sidebar

Related Questions

I want to be able to send a message from my mkmapview delegate class
I want to be able to send e-mail from my own domain (Domain.com) over
I want to be able to send files from an iPhone app to a
I want to be able to send arbitrary messages from my iphone to the
I want to be able to send messages to a remote JBoss server (JBoss
I want to be able to send a simple http post from my firefox
I'm writing my own WSGI Simple Server. I want to be able to send
I want to be able to send video stream from my application to a
I want to be able to send a simple post from an ASP code.
I want to be able to send all the selected values from a listbox

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.