node. JS Express MVC Lightweight Framework Practice

Source: Internet
Author: User

This document is the author's recent private time to do a friend to do a constant color automatic betting system, relatively simple, mainly to learn about node. js.

In fact, there is nothing to deepin talk logic, the main thing is to talk about this set of code structure. Structures such as:

JS code is difficult to maintain, it is unclear whether we agree to this point, but here the author only said his feelings, the author of my friend began to find the author, said to play always color, have been staring at play, will because of greed will be chaotic, want to do an automatic betting system, let the program itself play. At first, I just want to muddle through, directly take node.js+express the following structure.

The basic and Express sample code is no different. But with the change of demand, feel more and more difficult to maintain, helpless, can only re-come again.

This set of node. JS Express MVC code Structure I was learning Nodeclub Open Source project come, interested friends can go to study under. A brief description of the meanings of the parts in the code:

API-------------------> API logic Processing layer, generally is the curd of data and other operations

Controllers--------> C End Site, nothing to say

Jobs-----------------> Timed tasks, combined with Node-schedule

Logs-----------------> file log

Models------------> Mongoose Database links and individual entity definitions

Proxy--------------> Database access method encapsulation, such as INSERT, update

Util------------------> Tools JS package, such as DateFormat

Views--------------> Page layer, Ejs page rendering engine

Api_router.js-----> API Routing

Web_router.js---> web page routing

App.js-------------> Play Express know what this file does.

Why do I do this? MVC code layering, although the amount of the invisible increase in code, but the purpose is to better management, means a substantial reduction in maintenance costs, advantages outweigh the disadvantages.

Here by the way. node-schedule and pm2 process Manager in multi-process mode, there will be a recurring problem, the author's solution is to divide the web and jobs into multiple process manager management.

node. JS Express MVC Lightweight Framework Practice

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.