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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:17:15+00:00 2026-06-06T23:17:15+00:00

I have a simple webapp using node.js that reads the database and displays this

  • 0

I have a simple webapp using node.js that reads the database and displays this data to the user. There is this issue where after the app isn’t actively used, when viewed initially the connection errors out with a [Error: connection closed]. After reloading the connection seems to be ok, though it does seem to bomb randomly after it first happens and you are clicking around (which I’m pretty sure is one of the workers dying from a bad connection and restarting). Here’s pretty much all the important bits of the code…

//POSTPROVIDER.JS
var mongoose = require('mongoose');
var async = require('async');

var settings = require('./settings.js').mongodb;
if(!settings) {
  console.log('Could not connect to MongoDB server - missing MongoDB settings');
}

var connectString = "mongodb://" +
  settings.username + ":" + settings.password + "@" +
  settings.hostname + ":" + settings.hostport + "/" +
  settings.database;


mongoose.connect(connectString);

mongoose.connection.on('error', function(error) {
  console.log(error)
  mongoose.connect(connectString);
})

var Schema = mongoose.Schema;

var FeedbackSchema  = new Schema({
  //Schema
});

var feedbackDoc = mongoose.model('Feedback', FeedbackSchema);

//Example query
PostProvider.prototype.findByUuid = function(_id, callback) {

  feedbackDoc.findById( _id).exclude('screenshot').exec(function (err, feedback) {
    if (err) return callback(err);

    var feedbacks = JSON.stringify(convertFeedback(feedback), null, '    ');

    callback( null, feedbacks )
  });

};

exports.PostProvider = PostProvider;

And the server code…

//APP.JS    
var express = require('express');
var request = require('request');
var cluster = require('cluster');
var numCPUs = require('os').cpus().length;

var app = module.exports = express.createServer();

// Express Config
var pub = __dirname + '/public';

app.configure(function(){
  app.set('views', __dirname + '/views');
  app.set('view engine', 'ejs');
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(express.compiler({ src: pub, enable: ['sass'] }));
  app.use(express.static(pub));
  app.use(app.router);
});

var error = require('./error');

app.configure('development', function(){
  app.use(error({ showMessage: true, dumpExceptions: true, showStack: true, logErrors: __dirname + '/log/error_log' }));
});

app.configure('production', function(){
  app.use(error({ showMessage: true, dumpExceptions: true, showStack: true, logErrors: __dirname + '/log/error_log' }));
});

var PostProvider = require('./postprovider').PostProvider;
var PostProvider= new PostProvider();


if (cluster.isMaster) {
  // Fork workers.

  console.log("Master is running.  [ %d ]", process.pid );
  for (var i = 0; i < numCPUs; i++) {
    cluster.fork();
  }

  cluster.on('death', function(worker) {
    console.log('worker ' + worker.pid + ' died');
    console.log(worker)
    cluster.fork();
  });
} else {
  // Worker processes have a http server.();
    console.log("Worker is running.  [ %d ]", process.pid );

  //Main View
  app.get('/', function(req, res){

    var pageNum = 1;

      res.render('layout', {
            locals: {
              title: 'View Portal',
              pageNum: pageNum
            }
      });
  });

  app.listen(8900);
  console.log("Express server listening on port 8900");    
}

Is there a way to check the status of the connection, and if so a way to reconnect correctly before processing a query?

  • 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-06T23:17:16+00:00Added an answer on June 6, 2026 at 11:17 pm

    With the new version of Node, the application in question has to be rewritten. Answering my own question to close this out.

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

Sidebar

Related Questions

I wrote a simple webapp using google app engine in python that allows users
I have a webapp that lets you run querys from a DB using a
I have a problem using HtmlDataTable for viewing data from database. When I create
I have a webapp that uses Forms Authentication using ActiveDirectoryMembershipProvider. That works fine... users
Seems like a simple task. I have a webapp which requires a database connection.
Ok so I have a pretty simple webapp using a Servlet and in some
I have created a simple web app/form using google app engine. the site is
So I have a simple web app where I can create a user (UserModel)
I'm writing a simple web app in PHP that needs to have write access
I've been asked to create a stand-alone webapp using straight HTML and Javascript that

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.