Welcome to MEAGER NodeJs Framework

Meager is light weight MVC framework for NodeJS, which comes with simplified solution for complex structure.
meager mvc

MVC

MVC is a framework for building applications

  • Model = DataBase
    A Model , which represents the logical structure of data (DB - schema) in a application.
  • View = HTML
    A View , which is a collection of elements in the user interface (all of the things the user can see and respond to on the screen, such as buttons, display boxes).
  • Controller = Business Logic and everything else.
    A Controller , which represents the classes connecting the model and the view, and is used to communicate between classes in the model and view. In simple words business logic will be written here. It will be compiled or processed before View part gets load.

Routes

The URL pattern is considered only after domain name part in the URL. For example, the URL pattern "http://localhost/{controller}/{action}/{id}".
meager routes
The following table shows which Controller, Action method and Id parameter would handle different URLs considering above default route.
URL Controller
application/controllers/
Action Template
application/templates/
Parameters
http://localhost/users/register usersController.js register() users/register.html null
http://localhost/users/register/acc_type usersController.js register() users/register.html ['acctype']
http://localhost/users/register/acc_type/param2 usersController.js register() users/register.html ['acctype','param2']
http://localhost/users/login usersController.js login() users/login.html null

Example :- http://localhost/users/register
         
          //file  application/controllers/usersController.js
           
            module.exports ={
               usersController:class {
                 register(){ //Action here
                       
                    }
               }
            }
            
        

Router Rewrite

We can add multiple custom routes with different names, for example we can map http://localhost/members/signin to usersController and login() method. To do this need to add particulars in application/config/router.js , which has been shown in following lines.

      
         module.exports ={
           ROUTES: [
             {
               path:'users/login/',
               //  ---- for dynamic parameters ----
               // path:'users/login/**',
               redirect : {
                controller:'users', action:'signin', param:[]
               }
            }
           // use comma and add more

         ]};
        
      
Note :-
You can define routes with different path which are not having controller or action or both. Use /** to compile dynamic parameters. The param:[] component will help you to bind extra parameters which also be combined with dynamic url parameters, If you used /** in path.

Router Parameters Inside Controller

Calling Router parameters like ControllerName, Action, Params and Base URL inside the Controller Class.

      
         module.exports ={

            MEAGER:{
              scope:{ }
            },


          usersController:class {
            constructor(MEAGER){   
               this.routes = MEAGER.routes; 
            }
           }
         }
        
      


Utilities Class

Availabel Functions

  • Encrypt
  • Decrypt

Encryption / Decryption

1. Default Config

* Need to change DFAULT->encryption->key = "azAZ09" a-z A-Z 0-9

2. Inside constructor() of current Controller

    
    constructor(MEAGER){
      this.utilities = this.MEAGER.utilities;
    }
    
    
    
        let encrypted = this.utilities.encrypt('hello 123');
        let decrypted = this.utilities.decrypt(encrypted);
    
  

Post Method

Fetch data from POST method

    
        this.postData.then(res=>{ console.log(res); });  
    
  

MongoDriver

Inside constructor() of current Controller

      
         module.exports ={

            MEAGER:{
              scope:{
               mongo:true
              }
            },


          usersController:class {
            constructor(MEAGER){   
               this.mongo = MEAGER.imports.mongo; 
            }
           }
         }
        
      

Fetch / Find - Query

     
     // To Fetch without filters
       this.mongo.find({ },'users')
      .then(dbData=>{
             // dbData will contain json records
         })
      .catch(error=>{
            console.log('Error !',error); 
         }); 
    
    
    // To Fetch with filters *
       this.mongo.find({
           name:'arun',
           password:'123', 
        },'users')
      .then(res=>{
             // dbData will contain json records
         })
      .catch(error=>{
            console.log('Error !',error); 
         }); 
    
  

Insert - Query

    
       this.mongo.insert({
           name:'arun',
           password:'123',
           mobile:'87867676577'
        },'users')
      .then(res=>{
             if(res=='success'){

            }
         })
      .catch(error=>{
            console.log('Error !',error); 
         }); 
    
  

Update - Query

    
       this.mongo.update({
           name:'arun',
        },{
         name : 'new name here'
        },'users')
      .then(res=>{
             if(res=='success'){

            }
         })
      .catch(error=>{
            console.log('Error !',error); 
         }); 
    
  

Remove - Query

    
       this.mongo.remove({
           name:'arun',
        },'users')
      .then(res=>{
             if(res=='success'){

            }
         })
      .catch(error=>{
            console.log('Error !',error); 
         }); 
    
  

Count - Query

    
       this.mongo.count({
           name:'arun',
        },'users')
      .then(res=>{
             // res will have count of records
         })
      .catch(error=>{
            console.log('Error !',error); 
         }); 
    
  

Download Meager Framework

      
        npm install meagerjs
      
    
      
        meagerjs_clone
      
    
      
        cd meagerjs
      
    
      
        node start