Skip to content

A page for a travel agency startup built on top of NodeJS and NextJS.

Notifications You must be signed in to change notification settings

nolzart/node-natours

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

99 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Natours

A page for a travel agency startup built on top of NodeJS and NextJS, here is the live version

Description

Natours is an application where the API is built with NodeJS and express. the frontend created in Nextjs is served by node. Once you enter the main page, all the tours available in the application will be displayed, each tour has a button that guides you to the details section, in this you can see all the information related to the tour, such as the routes to follow with mapboxgl and user reviews, at the end you will find a section to buy the tour with your credit card using stripejs checkout, to access the application you can use the route /login or /signup. All authentication and authorization is handled with JWT and cookies.

Few Requirements

Key Features

  • Authentication and Authorization
    • Sign up, Log in and Log out
  • Tour
    • See tour guides, check the tour route with maps, check user reviews, ratings and book the tour
  • User Profile
    • Update username, photo, email and password
  • Credit card payment

How To Use

Book a tour

  • Log in to the site.
  • Choose the tour you like the most.
  • Book a tour.
  • You will be redirected to the payment page.
  • Enter the card details (Stripe is in test mode).
  • - Card No: 4242 4242 4242 4242
    - Expiry date: 02 / 24
    - CVV: 222
    

Manage your booking

  • On the account settings page, you will find a button in the "Manage Booking" navigation that will show you the tours you have booked.

Update your profile

  • On the account settings page, you can update your own username, profile photo, email and password.

API usage

Before using the API, you need to set the variables in your API testing (like Postman or Insomnia) depending on your enviroment.

- {{URL}} with your hostname as value (Eg. http://127.0.0.1:3000 or https://www.production.com)
- {{JWT}} with your Json Web Token as value.
    

API Features

Filtering 👉 You can include filters in the URL by including additional query parameters. To start filtering add a ? followed by the query [query]=[value]. If you want to chain several queries in the same call, use & followed by the query.

For example/api/v1/tours?duration=7&maxGroupSize=15

You can use mongoose operators, specifying the operator you want to use encapsulation in brackets in front of the property

For Example: api/v1/tours?duration[gte]=5&price[lte]=2000

Sorting 👉 You can sort results based on a certain field using sortparameter.

For Example: api/v1/tours?sort=price upward

api/v1/tours?sort=-price falling

Limit Fields 👉 You can specify which fields you want to get back in the response using the fields parameter.

For example: api/v1/tours?fields=name the response will return the name field.

api/v1/tours?fields=-guides the response will not return the guides field.

Pagination 👉 You can select a certain page of the results using the limit parameter to indicate how many results you want per page and the page parameter to indicate the page.

For exapmle api/v1/tours?page=2&limit=3

Tours List 👉 return all tours https://mern-natours.herokuapp.com/api/v1/tours

Tour Stats 👉 returns the statistics of all tours https://mern-natours.herokuapp.com/api/v1/tours/tours-stats

Get Tours Within Radius 👉 It shows the cheapest tours and the ones that are best rated by users https://mern-natours.herokuapp.com/api/v1/tours/top-5-cheap

Get Tours Within Radius 👉 You can get tours around a certain area, specifying the coordinates (in the form of lat, lng), the distance and the unit (mi or km)

/tours-within/distance/:distance/center/:latlng/unit/:unit 👉 https://mern-natours.herokuapp.com/api/v1/tours/tours-within/distance/200/center/34.371714,%20-117.825382/unit/mi

Enviroment Variables

Server and Database Keys

  1. NODE_ENV 👉 node enviroment (development or production)
  2. PORT
  3. DATABASE 👉 Hosted database
  4. DATABASE_PASSWORD 👉 Hosted database password

Authentication Keys

  1. JWT_SECRET 👉 Generate your secret jwt key
  2. JWT_EXPIRES_IN 👉 expiration time of jwt
  3. JWT_COOKIE_EXPIRES_IN 👉 expiration time of cookie

Email Keys

  1. EMAIL_HOST 👉 Mailtrap host
  2. EMAIL_PORT 👉 Mailtrap port
  3. EMAIL_USERNAME 👉 Mailtrap username
  4. EMAIL_PASSWORD 👉 Your mailtrap password

Admin details

  1. EMAIL_FROM 👉 receiver will see this email of admin in his email
  2. SENDGRID_USERNAME 👉 Sengrid username
  3. SENDGRID_PASSWORD 👉 Sengrid password
  4. SENGRID_API_KEY 👉 Your sengrid api key

Stripe Keys

  1. STRIPE_API_KEY 👉 Your stripe secret key

Build With

  • NodeJS 👉 JS runtime enviroment
  • ExpressJS 👉 Web framework for Node.js
  • NextJS 👉 The react framework for production
  • Redux 👉 A Predictable State Container for JS Apps
  • SASS 👉 CSS extension language
  • Mongoose 👉 MongoDB object modeling for node.js
  • MongoDB Atlas 👉 Cloud database service
  • JSON Web Token 👉 open, industry standard RFC 7519 method for representing claims securely between two parties
  • Stripe 👉 Payments infrastructure for the internet
  • Mailtrap & Sengrid 👉 Email Delivery Service
  • Heroku 👉 Cloud platform

Acknowledgement

The API and design for this project are part of a udemy online course I did. building the frontend with nextjs is my own work 😎. Thanks to Jonas Schmedtmann for this great course.