In order to separate the business logic and data access layer , I have separated the files and folders in a non-event driven way. Here is an example of the User signup process I have taken , Here is my Business logic layer file.
var userDA = require('./../DataAccess/UserDA');
module.exports = {
signUpUser: function(userGiven)
{
//Some bookeeping
userGiven.userType = "admin";
return userDA.save(tutorGiven);
}
}
and here is my data access file
"use strict";
var mongoose = require('mongoose');
if(!mongoose.connection)
mongoose.connect('mongodb://localhost/test');
var User = require('./../models/User');
module.exports ={
save : function(UserGiven){
var pass = true;
var user = new User(UserGiven);
user.save(function (err) {
if(err) {
console.log(err);
pass = false;
}
});
return pass;
},
getUser: function (email) {
var user = null;
user.findOne({email:email},function(err,foundUser){
if(err)
console.log(err);
else
user = foundUser;
});
return user;
}
}
This a for a real project of medium-large size , and as a newcomer in nodejs I was wondering and in need of an expert advice if It would be any problem if I take this kind of designing approach?