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

  • Home
  • SEARCH
  • 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 9178279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:30:53+00:00 2026-06-17T17:30:53+00:00

I am working on a nodejs app. Folder structure is app app.js package.json ../model/schema.js

  • 0

I am working on a nodejs app.

Folder structure is

app
app.js
package.json
../model/schema.js
../controller/controller.js
../views

All the logic is in controller.js while app.js performing routing itself….

I want to know how to get/return data(object) from controller.js to app.js.

I am using ‘return’ to send mongodb document from controller to app but its undefined.

Heres code of app.js..i have removed unneccessary code

  var express = require('express'),
   app = express.createServer(express.logger()),
   io = require('socket.io').listen(app),
   routes = require('./routes');
   var controller=require('./controller/controller');
   var model=require('./model/schema');

   app.get("/", function(req, res) {
     res.render("chatroom.html");
    });

   io.sockets.on('connection', function (socket) {
      socket.on('login',function(user)
      {
          var onliner=controller.loginUser(user);
          console.log("Onlinersss: ",onliner);
      });

      socket.on('registerUser',function(user){
          controller.registerUser(user);
      });
   });

Heres controller.js code:

  var model=require('../model/schema');
  exports.loginUser=function(user)
  {

      model.registerUser.findOne({uname:user.uname,pass:user.pass},function(err,doc){
        if(!err){ 
             console.log("Here loggedin: ",doc); 
             return doc;             
        }
        else
             console.log("Invalid username or password");
        });
  };
  • 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-17T17:30:54+00:00Added an answer on June 17, 2026 at 5:30 pm

    I’ve just pushed a project to GitHub that uses pretty much the same libraries and RethinkDB as the database (very similar to MongoDB). Basically you need to pass callbacks to your controller and have them invoked with the data retrieved from the DB. Take a look at app.js and lib/db.js in the linked project.

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

Sidebar

Related Questions

I've been working with node.js for a while on a chat app (I know,
For the past 6 months, I've been working on my own nodeJS app, where
Currently i'm working on an NodeJS app building over RailwayJS framework. I would like
I am working on a nodejs/express app with Mongodb on the backend. In one
I'm working on a NodeJS+Mongodb app. I've just inserted one record into mongodb using
I am working onr a backbone.js app, where one of my views is a
I have recently been working on a nodejs app which uses open socket connections
I'm working on a small NodeJS app that uses everyauth (technically mongooseAuth) to talk
I am working on an user space app for an embedded Linux project using
I'm working with a Hobo app using the input_many tag to handle a many-to-many

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.