Base application with mongodb + expressjs

1. Tạo project tên blog
express blog
|   app.js
|   package.json
    │   www
    │   Blog.js
    │   db.js
    |   blog.js
    │   index.js
    │   error.jade
    |   index.jade
    |   layout.jade
        │   edit.jade
        │   index.jade
        |   new.jade
2. set up mongoDB brew update
brew install mongodb
MongoDB shell 
use blogdb 
3. Setup Monogoose for mongoDB 
models/ db.js: kết nối vs mongoDB 
var mongoose = require('mongoose'); 
add db.js on app.js 
db = require('./models/db'),
4. Install Dependencies
npm install npm install mongoose --save 
npm install body-parser --save
npm install method-override --save 
5. Create the Model and Schema 
var mongoose = require('mongoose'); 
var blogSchema = new mongoose.Schema({ 
 title: String, 
 content: Number, 
 pushed_date: { type: Date, default: }
mongoose.model('Blog', blogSchema); 
add Blog.js on app.js 
blog = require('./models/Blog'), 
6. Create the Controller 
7. Add The Route on app.js
var blog = require('./routes/blog');
app.use('/blog', blog); 
8. Add The Views

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s