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