Welcome to TravelCamp!
A Travel Blog where everyone can create their own travel posts and view other users' experiences, as well as give reviews or contact with the posts' owners. As long as you sign up and log in, the whole blog is yours!
Built in cloud9 - a powerful online code editor with a full Ubuntu workspace in the cloud.
- If built with cloud 9, click here
- If built locally on Windows 10, installing mongodDB (currently mine is version 3.6)
*** In case cannot run command
mongod
on Git Bash due to command not found and/or you haven't set up MongoDB environment, check Youtube tutorial or official MongoDB documentation
npm install
- express (Server-side Javascript)
- ejs (Embedded Javascript)
- body-parser (middleware: convert form data requests from user under
req.body
property as an object) - mongoose (mongoDB for Express version)
- method-override (used for method PUT and DELETE in RESTful ROUTE that form type in cliend-side doesn't support
- connect-flash (middleware: store message displayed for user once and cleared after page being refreshed)
- passport
- passport-local
- passport-local-mongoose
- express-session
node app.js
- It will direct to localhost:3000
- The differences between Authentication and Authorization:
- Authentication: get people signup/login. In other words, people need to tell app/website who they are.
- Authorization: Once figure out who user is, grant permission on specific things they are allowed to do.
- How To Do?
- Hint:
- Verify the id of current user with id of author who creates the post
- However, id of current user - a string (req.user._id) is different than id of author (foundBlog.author.id) - a mongoose object
- Instead of using: if(req.user._id === foundBlog.author.id). We use:
if(foundBlog.author.id.equals(req.user._id)){ ... }
After project is done:
- In package.json:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js"
}
- Setup your mlab before publishing project to heroku:
- Name new database
- Create new user
- Replace code line in app.js:
mongoose.connect("mongodb://<dbuser>:<dbpassword>@ds245228.mlab.com:45228/travelcamp")
- git cmd
git init
git add .
git commit -m "heroku deploy"
heroku create [app-name]
(login and create new app, download Heroku CLI)git push heroku master
=> done!
- Or when you delete your current heroku app and want to deploy again:
git remote set-url heroku <new heroku git url>
git push heroku master
=> done!