Overview of Web microblogging system based on node and MongoDB
The project was inspired by the "node. JS Development Guide", where the author Byvoid was the first Node developer at the time, and the learner desperately needed a demo. Of course, it has been many years, node has been updated countless times, the 12 book is outdated, many code is not run through, and finally to the official website API prevail.
- Background of the project with Express.
- The database section itself writes native MongoDB, does not go with the more powerful control mongoose frame, writes the native thing to oneself to have the benefit.
- The front end is jquery,underscore.js.
- The bootstrap frame used for the style.
Design
The formal adoption is the MVC structure, the database and the encryption part in the model layer, the route control acts as the Controller,ejs front-end display is the view layer.
Installation dependencies
"dependencies": { "ejs": "^2.5.7", "express": "^4.16.2", "express-session": "^1.15.6", "formidable": "^1.1.1", "gm": "^1.23.0", "mongodb": "^2.2.33" }
If you want to develop two times, Node--modules section recommended to follow the above version of their own npm install, my node version is v8.3.0, the latest is v8.9.0
Features and implementations
- Login module, registration module, the publication of Weibo, all users of micro-blog, all the user's Weibo, all Users list, click on a user can see the user posted Weibo, user exit, Avatar upload and cut, after landing directly click on their default avatar can go to the Avatar upload page, The homepage presents different pages depending on the login status.
- The judgment of State is passed by Express-session.
- The server to the Avatar picture processing used to GraphicsMagick, this plugin can intercept screen, and then I wrote a script to get to this plugin screen size parameters, the front-end interface to do the picture clipping.
- Database on the MONGO of additions and deletions and paging function compared to the original, direct reference to the official website MONGO to Nodejs Open API, some operations to implement the overloaded, JS is no function overload, can only own handwriting judgment, such as query operation find function, can be overloaded according to different parameters, Judging by the number of parameters, it is true that the results of the query are not sorted, paged, skipped, and restricted.
- Weibo display part, used to underscore.js, because and Ejs template tag coincident, I modified the underscore source code, the template tag <%%> became {{}}. All micro-blog display processing, because the user's information is present within the user collection, Weibo exists in the posts collection, MONGO not like the MySQL traditional relational database, there is no foreign key, I get all the microblog when the query is posts collection, Posts collection there is no user's avatar, I want to display the user's avatar in all Weibo, had to use the double Ajax callback, the first layer to get to all said, the second layer in the iterator, the iterator is a recursive, in order to pagination effect, with the implementation of the closure of the iterator, which is JS pit who use who know. (Of course ES6 can solve this problem easily), the iterator obtains the first level callback result the username, then queries obtains to the avatar, then merges to the first query result.
- There are some other things that interest can be fork,clone to see the source code.
Pending improvement
Weibo comments, like the function, the homepage of each microblogging function, etc., can fill the pit there are many, but the general framework is written well, open source is also hope that we can add functionality together.
Conclusion
This project is used to practice node better, code comments write a lot, if this project to you have a little bit of help, Ask a star, also welcome fork, together with more features.
DEMO
Code:
GitHub Warehouse
Some questions can be commented, Issue, or buckle 1104272319 contact me.
Web microblogging system based on node and MongoDB