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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:34:36+00:00 2026-06-05T18:34:36+00:00

in my self-defined module I have this method which will query the db and

  • 0

in my self-defined module I have this method which will query the db and find if the username exists in my db. I want some values to be returned so in the upper level I will know the query result.

var findUserbyUsername=function(username)
{
    db.users.find({email:username},function(err,result)
    { 

        if(err|!username) {console.log('username not found'); return 0;} 
        else return 1;
    }
    );
}
module.exports.findUser=findUserbyUsername;

in app.js I will call the above method like this

var lt=dbutil.findUser('xxxx@gmail.com');

but unfortunately I got undefined….
Can anyone help me workaround this ? Or any other suggestions ?

  • 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-05T18:34:38+00:00Added an answer on June 5, 2026 at 6:34 pm

    This is an asynchronous code, of course it’s not going to return anything. You might want the following:

    app.js:

    dbutil.findUser( 'xx@gmail.com', function( err, data ) {
        if ( err ) throw err;
        // Handle the datas returned "data"
    } );
    

    module:

    var findUserByUserName = function( username, callback ) {
        db.users.find( { email: username }, function( err, result ) {
           if ( err || !username ) {
               console.log( 'username not found' );
    
               // Call the function passed as parameter
               callback( err ); // You give "undefined" as second parameter
           }
           else {
               callback( err, result ); // You give the datas back
           }
        } );
    } );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say that I have a class defined in moduleA.py which I want to
I have this situation, in which I define an instance method which returns a
I want to create a large (~300,000 entries) List of self defined objects of
So I have a self-joining model defined. Basically a post on a forum, and
I have a before_save defined as follows: def before_save self.token = generate_token end I
I have the following program. module C def self.included(base) base.extend(ClassMethods) end module ClassMethods def
i have the following code in a module called code_database.py class Entry(): def enter_data(self):
More verbosely, I have a module Narf , which provides essential features to a
I have a problem similar to the first problem in this question , which
If I have Foo::Bar written in Ruby, and I want to add a method

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.