Web microblogging system based on node and MongoDB

Source: Internet
Author: User

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.

    1. Background of the project with Express.
    2. 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.
    3. The front end is jquery,underscore.js.
    4. 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
    1. 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.
    2. The judgment of State is passed by Express-session.
    3. 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.
    4. 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.
    5. 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.
    6. 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

Related Article

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.