(-?-;), 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:
- Express New Project
- Express comes with the use of the Jade template engine
- Express's routing Management
- Rights Management in Express
- 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)
- Underscore the use of front-end templates
- Grunt Nodemon module and concurrent module use method;
- 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