This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mongoose.connect('INSERT YOUR DATABASE URI HERE'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var mongoose = require('mongoose'); | |
| var postSchema = mongoose.Schema({ | |
| title: { type: String, required: true }, | |
| text: { type: String, required: true }, | |
| date: { type: Date, required: true } | |
| }); | |
| var post = mongoose.model('post', postSchema); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Post = require('../models/post'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| router.post('/', function(req, res) { | |
| // interact with the model here | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| router.post('/', function(req, res) { | |
| if (!req.body.title || !req.body.text) { | |
| return res.redirect('/'); | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| router.post('/', function(req, res) { | |
| if (!req.body.title || !req.body.text) { | |
| return res.redirect('/'); | |
| } | |
| var post = new Post({ | |
| title: req.body.title, | |
| text: req.body.text, | |
| date: (new Date()) | |
| }); | |
| post.save(function(err) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| router.get('/', function(req, res) { | |
| Post.find(function(err, posts) { | |
| res.render('index', { | |
| title: 'my Blog!', | |
| posts: posts | |
| }); | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| hr | |
| each post in posts | |
| h4= post.title | |
| span= post.date | |
| p= post.text |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| web: node bin/www |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| node_modules |