You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 05_Sports_Blog/README.md
+19-10Lines changed: 19 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -1,24 +1,29 @@
1
1
# Sports Blog
2
2
3
-
>## Sports Blog Demo - Web View
3
+
>## Sports Blog Demo - Web View
4
4
5
5

6
6
7
-
8
-
>## Mobile View
7
+
> ## Mobile View
9
8
10
9

11
10
12
-
13
11
## 05_01 Project Intro
14
12
15
13
- We will create a Sports Blog with full CRUD functionality. We will use mongoose this time around. It is another method of connecting to MongoDB, and is more advanced than standard MongoDB driver which we used in last project of TODO App. It's more efficient, advanced and sort of more intuitive to connect to NoSQL DB.
14
+
16
15
- Functionality also includes visitors being able to post comments on every blog post.
16
+
17
17
- We have category sort available as well on blog. Where users can sort as per their choice.
18
+
18
19
- Admin features such as being able to add and remove categories along with notification messages whenever there is some edit done.
20
+
19
21
- Same functionality available to manage articles also available.
22
+
20
23
- Use of data and time formatter to present Data, Time in a more clean manner.
24
+
21
25
- Form validation as well.
26
+
22
27
- Run MongoDB in docker using `sudo docker run -d -p 27017:27017 -v ~/data:/data/db mongo`, visit [this](https://www.thachmai.info/2015/04/30/running-mongodb-container/) for detailed info.
23
28
24
29
- Or you can do this to remove related to mongoDB if you have any, I'd recommend Docker:
- We will proceed in same manner as we did for **PC Repair** website such as using external routing files, Pug template engine, but this time we won't use express generator, rather we will set everything up from scratch and create our own app.js file as this gives us less limitations and more flexibility while setting up our project.
67
+
62
68
- We have a lot more dependencies for this app. So instead of doing npm install --save, we will directly put all of our requirements in package.json file so that we can just run npm install and it will set it up everything in one go.
63
69
64
70
- See the docs for express-messages and validator on these links: [Validator](https://express-validator.github.io/docs/), [messages](https://github.com/visionmedia/express-messages)
@@ -77,9 +83,11 @@ sudo service mongodb stop
77
83
78
84
## 05_05 Fetching Categories and Working with Mongoose
79
85
80
-
- Create db and add categories using the following
86
+
- Create db and add categories using the following, db.createCollection docs [here](https://docs.mongodb.com/manual/reference/method/db.createCollection/)
81
87
82
-
```
88
+

89
+
90
+
```sql
83
91
use sportsblog
84
92
db.createCollection('categories')
85
93
db.createCollection('articles')
@@ -89,6 +97,7 @@ db.categories.insert({title:'Football','description':'These are Football article
89
97
db.categories.insert({title:'Cricket','description':'These are Cricket articles.'})
90
98
db.categories.find()
91
99
```
100
+
92
101
- Now we have 4 categories in our DB, next want to fetch these categories using Mongoose. In Mongoose we deal with models, create a directory called models and inside it create a file called `category.js`. We try keeping everything encapsulated inside module.
93
102
- To connect to mongoose, we go to app.js and define the required methods. After doing mongoose.connection go to `routes/categories.js` and bring up Category model. Now on visiting localhost:5000/categories you would see all the categories and description in the console. Next we want to take those categories and pass them into our template of categories page.
94
103
- Next we work on implementing functionality for `/manage/categories/add` route using a form we would be able to add new categories.
@@ -149,7 +158,7 @@ db.categories.find()
149
158
150
159
## 05_10 Messages
151
160
152
-
- To show a message we can see that in the route /manage/categories when we add something and do a res.redirect, before that we can send a flash message. We can do so by entering the following `req.flash('Success', 'Added To Category')` after that we go to app.js and setup connect-flash and we use a variable globally called messages which we may use in our templates to show messages. So we should add the message in `/manage/categories/` route as that's where we will be redirected once we submit the request successfully. Make some changes to style.css and messages will work on your page.
161
+
- To show a message we can see that in the route /manage/categories when we add something and do a res.redirect, before that we can send a flash message. We can do so by entering the following `req.flash('Success', 'Added To Category')` after that we go to app.js and setup connect-flash and we use a variable globally called messages which we may use in our templates to show messages. So we should add the message in `/manage/categories/` route as that's where we will be redirected once we submit the request successfully. Make some changes to style.css and messages will work on your page.
153
162
- On adding articles also we want the same effect, so we go to articles.js and before the redirect request we do the same as we did for categories.
154
163
- With messages showing up on Add and Edit for category and articles we are done with admin side or things related to controlling the content on the site.
0 commit comments