Use EXPRESS4. X + Jade + Mongoose + underscore to build a personal movie site

Source: Internet
Author: User
Tags findone

(-?-;), the weekend is really fast ah, a long time ago saw Imooc on a personal movie site, a two-period video, the two weeks House home to play nothing dry, I also learned to build a, these things are the basis, as long as the time is very studious, Nodejs This stuff is light weight, where is uncomfortable.

  If you learn to write, you can learn:

    1. Express New Project
    2. Express comes with the use of the Jade template engine
    3. Express's routing Management
    4. Rights Management in Express
    5. How Express is combined with mongoose, and how the schema and model are used in mongoose, and CRUD (you know-do I say O (^▽^) o)
    6. Underscore the use of front-end templates
    7. Grunt Nodemon module and concurrent module use method;
    8. How to save the user's information (session) by mongo-connect this NPM module;

....

The entire Web page consists of the following four modules:

Homepage (?? ω??) y; List Page Movie Detail page manage page movie new movie delete movie info edit Register login log out
Rights Management through routing
Comments from users commenting on each other

The GitHub address offered by Scott Nodejs, a lecturer at the Web, is: Open, this project's Express is 3.x series, so the use of the Express4.x series certainly won't run up, and then I wrote myself a 4.x, GitHub project address is: No , but you can click here to download the source code, as a reference for learning, and so I put the interface to do a beautiful point, better function when the transfer git;

The main directory structure of the project is similar to the usual express default structure

The project relies on a lot of modules .... The whole installation is good;

In fact bower, less and jslint, mocha, karma, Kaola .... I have no use, too high-end can not be used up. the tools are really too many ;

The main interface is probably like this, you can get a sneak peek:

  video interface as follows , the new video when the address is filled by default has a Youku video address, the image is the default blog Park logo image ;

 

It is important to define the static and instance methods of the model in mongoose, and to specify _id fields by setting the table of the field type to associate references to Objectid, I post some code to prevent forgetting:

varMongoose = require ("Mongoose");varObjectId =Mongoose. Schema.types.objectid;console.log (Mongoose. SCHEMA.TYPES.OBJECTID)varCommentschema =NewMongoose. Schema ({movie_id:string, replys: [{to: {//corresponds to a cell that references a _id value below the user tableType:objectid, ref:"Userschema"}, from: {Type:objectid, ref:"Userschema"}, Content:string, time: {type:string,default: Date.now ()}} ]}); Commentschema.statics={fetch:function(CB) {return  This. Find ({}). exec (CB); }, FindByID:function(ID,CB) {return  This. FindOne ({_id:id}). EXEC (CB); }, Findbymovieid:function(MOVIE_ID,CB) {return  This. FindOne ({movie_id:movie_id}). EXEC (CB)}, Findbymovieidexec:function(movie_id) {return  This. FindOne ({movie_id:movie_id}); }};//This method is called each time it is saved;Commentschema.pre ("Save",function(Next) {Next ();});//This data model is defined for MongoDB, and the data model is bound to the current database;                                       //This is the table name inside the database;varComment = Mongoose.model ("Commentschema", Commentschema); Module.exports= Comment;


There are some improvements in the tutorial in the Web , such as the release of comments and pull me through Ajax real-time refresh get, as well as the deletion of the video interface, etc., also through the Ajax refresh, interface beautification (ignore this sentence) and so on;

End

Use EXPRESS4. X + Jade + Mongoose + underscore to build a personal movie site

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.