Monday, July 9, 2012

NodeJs - Basic Server Implementation With MVC Architecture

Here, I come back with Nodejs and MVC concept. Yes, I want to use Nodejs modules more easy and flexible way. Before get into deep, just go through the following diagram.

Unlike PHP+Apache, In NodeJs, the code is live until the application terminate once application is started. So any careless code will leads to memory-leaks. So before start, we have to plan about structure of project. That is, there should be clear definition about place of modules and how they are going to communicate each other. So here, I have proposed a design with support MVC which is showed in diagram. There is three kind of modules, First one is core modules like http, fs and more. Second one is contributed modules like request, underscore and more. And third type is custom modules which are developed by application developer. I have to organize these three modules in right folder/directory. Luckily, Core modules are comes with NodeJs installation setup. And Contributed modules are placed in folder named with "node_modules" by NPM. So I have to take care only about custom modules.

Here, I feel keep those custom modules or files in separate folder without joining them as a part of contributed module. I called this separate folder as "Application" which is showed in diagram. Since I have control over my code, I divide them three part to support MVC and organize the code in files based on their responsibilities.

And more, as showed in diagram, I would like to keep the communication of those modules in application folder more strong and communication of modules between "Application" folder and "node_modules" folder is in comfortable level. I mean, On incoming request the modules in "Application" folder talks strongly within themselves. In another word, during the application start-up, the modules within "node_modules" folder interact each other and generate a base. The modules in "Application" folder are interact often, that means on every request. Since "Express" module has great control on handling routing, session and request body parsing, I am using "Express" to gain controller advantage. Overall, The system handles the request with respective to MVC.

Note: You can fork it at anytime. Help to improve the code.

Output: Folder view

Note: Please write your queries and suggestion as comment.


  1. I am really enjoying reading your well written articles.
    It looks like you spend a lot of effort and time on your blog.
    I have bookmarked it and I am looking forward to reading new articles. Keep up the good work..
    PHP Training in Chennai
    PHP Course in Chennai
    Angularjs Training in Chennai
    CCNA Training in Chennai
    ui design course in chennai
    Salesforce Training in Chennai
    web designing training in chennai
    Tally Course in Chennai

  2. There are a number of plays of food show. This show is the greater podcast that can be watched at YouTube also. You would also like to listen about the Company where I do job which provides best creative writer India which can make your show more popular. New Gutter Installation company

  3. I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts.
    Cyber Security Projects for Final Year

    JavaScript Training in Chennai

    Project Centers in Chennai

    JavaScript Training in Chennai

  4. Thanks for your nice post, i am interested to learn online freelancing, but firstly i have to learn computer , could you suggest me please which computer training center best.

    Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery