Skip to content

Create a Fitness Tracker web applicaion with MongoDB, Mongoose schema and handle routes with Express, applying MVC Pattern then deploy to heroku.

Notifications You must be signed in to change notification settings

EunsooJung/Fitness-Tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Burger Web Application

Create a Fitness Tracker web applicaion with MongoDB, Mongoose schema and handle routes with Express, applying MVC Pattern then deploy to heroku.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

# Install body-parser
npm i body-parser

# Install middleware
npm i express

# CORS is a node.js package for providing a Connect/Express middleware that can be used to enable CORS with various options.
npm i cors

# Install dotenv: Dotenv is a zero-dependency module that loads environment variables from a .env file into process.env. Storing configuration in the environment separate from code is based on The Twelve-Factor App methodology.
npm i dotenv

# Run
node server.js or npm start (using nodemon)

Preview

Fitness-Tracker

Usage

Basic Usage

To get Fitness Tracker, after downloading, you need to make sure Git Bash terminal open and looking at the correct folder. When you are within the correct location, you may type the following commands to ask her for information:

  • node server.js

Guidelines:

  • Proceeds as follows:

To use this applicaion, Clone the applicaion to your local git repository or directory:

To start:

  • You have to install npm packages depend on my package.json file: "npm install"
  • Open your terminal then "node server.js"

Code Snippet

  • Project structure

    [Fitness-Tracker-Project-Structure]

  • Source Code Check point

  1. folder "models": It provides Mongoose Schema model
  const mongoose = require('mongoose');

  const Schema = mongoose.Schema;

  const ExerciseSchema = new Schema({
    type: String,
    name: String,
    duration: Number,
    weight: Number,
    reps: Number,
    sets: Number,
    distance: Number
  });

  const Exercise = mongoose.model('Exercise', ExerciseSchema);
    module.exports = Exercise;
  });
  }
  1. folder "public": As the view layer, it provides present html page and ui logic.
    • api.js: Main role is communicate with Server API
  async getLastWorkout() {
    let res;
    try {
      res = await fetch("/api/workouts");
    } catch (err) {
      console.log(err)
    }
    const json = await res.json();

    return json[json.length - 1];
  }
  1. Controller layer: Server-Side routes
  • Create all of this Fitness Tracker web application's routes (maps) using a exppress router.
// Provide all workouts
app.get('/api/workouts', (req, res) => {
  db.Workout.find({})
    .populate('exercises')
    .then(exercises => {
      res.json(exercises);
    })
    .catch(err => {
      res.json(err);
    });
});
  1. server.js:
    • Setup Fitness Tracker web applicaion's environments (npm package dependencies)
    • Import routes to access.
    • It provide MongoDB Atlas URI to connect cloud service
require('./routes/htmlRoutes')(app, path);
require('./routes/apiRoutes')(app);

Built With

Authors

  • Michael(Eunsoo)Jung

License

This project is licensed under the MIT License

About

Create a Fitness Tracker web applicaion with MongoDB, Mongoose schema and handle routes with Express, applying MVC Pattern then deploy to heroku.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published