Skip to content

A travel blog/website created by Node.js, Express.js and mongoDB on built-in Ubuntu workspace in the cloud. Utilize full CRUD operation and Auth.

Notifications You must be signed in to change notification settings

NinaDang97/travelcamp-express-mongo

Repository files navigation

TravelCamp

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.

Demo Version

travelCamp

Setup MongoDB

  1. If built with cloud 9, click here
  2. 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

Install and running app

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

Some definition during project:

  1. 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.
  1. 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)){
                   ...
           }
    

Heroku Deployment:

After project is done:

  1. In package.json:
"scripts": {
  "test": "echo \"Error: no test specified\" && exit 1",
  "start": "node app.js"
}
  1. 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")
  1. 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!

Inspired by Web Developer Bootcamp - Colt Steele

About

A travel blog/website created by Node.js, Express.js and mongoDB on built-in Ubuntu workspace in the cloud. Utilize full CRUD operation and Auth.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published