Skip to content

Instantly share code, notes, and snippets.

@ross-u
Last active January 31, 2021 18:42
Show Gist options
  • Save ross-u/84d3f5ccd74a13d06c3d92ffb729361b to your computer and use it in GitHub Desktop.
Save ross-u/84d3f5ccd74a13d06c3d92ffb729361b to your computer and use it in GitHub Desktop.
M2 - project structure (ExpressJS + Mongoose + JSX)

M2 - project setup (Node + ExpressJS + Mongoose + JSX)


Getting Started

README

The below steps should be done only once your project idea was verified by your captain and you have your documentation/README completed.

Fork

Fork 🍴 the starter code repository containing the M2 project sturcture. Only one person in the team should fork the starter code.

Change the repository name

In the fork of the repository, change the name of the repository to the name of the project


Add the repository Collaborator/s

The team member who is the owner of the repository should add the other team member as the Collaborator.

To do this, while on the page of the projects GitHub repository:

  1. Open the Settings tab.
  2. In the left-hand side menu select Manage access.
  3. Click on the button Invite a collaborator.
  4. Search for and add the other team member by the GitHub username or email.
  5. The other team member should accept the invitation (either by email that is automatically sent, or by the invitation link).

Clone the repository

Clone the repository of your project to your local environment.

After cloning the repository, open the project folder locally on your computer.


Set the environmental variables - .env

Change the name of the provided file .env.sample to .env.

After re-naming the file, update it's contents to do the following:

  • Update MONGODB_URI and add the name you want to use for your database at the end of the URL string
  • Update the SESSION_SECRET and add some random data.

After updating it, pass the content of the file via Slack or message to the other team member. This will ensure that you are both using the same environment setup and values during the development.


Inclued your README file in the project

Add the README.md file with the finished project documentation to the root directory of the project.


Create the .gitignore file

Create the .gitignore file in the root folder of the project.

touch .gitignore

Add the file/folder exclusion rules to the .gitignore file. You can find and copy the file content containing these rules from the .gitignore boilerplate for NodeJS projects on the GitHub's repo here.


❗ ❗ IMPORTANT: Double check that you have the .gitignore file, and that it contains a rule for the .env file which prevents this file from being uploaded to the repository and being visible publicly. This is very important. Please keep this in mind in your future projects which may contain API keys, session secrets, etc.


Git branches and GitFlow

Next step would be to create the develop branch locally and push it's copy to GitHub.

Create an additional develop branch (Your project will have 2 main branches master and develop)

While in the root folder of the project, run the following commands:

# Create a new branch - `develop`
git checkout -b develop

# Push the new branch to the GitHub repository
git push origin develop

Next step - Other team member/s

After the project/repository owner does the above steps and pushes the new branch and the updates to GitHub, the other team member/s should clone the repository and pull all the branches.

git clone <url-of-the-project-repo>

Once cloned the team member/s should navigate to the root directory of the cloned project and then run the follwing command to pull the develop branch:

git pull origin develop

Git Flow Main Guidelines

  • master branch will be used only for deployment.

  • develop branch will be used for working/development. When working on a feature create a new branch from develop.

    Tips to avoid merge conflicts:

    • Work on separate files, and communicate with your partner.
    • Initial setup of the back-end should preferably be done in pair, taking turns while coding and preferably coding on one laptop (pair programming).
    • Do a checkpoints with the partner and communicate things that you will be doing and parts of code that you will be working on.
    • Make smaller commits, and write descriptive messages:
      • Max. 50 characters (over 50 will wrap in the message body) )
      • Use imperative e.g. :
        • "Add session middleware to app.js "
        • "Add UserModel.js"
        • "Bugfix route '/login' in routes/auth.js "

    Working with branches:

    In the below examples the angle brackets <> indicate the identifier/parameter/argument values that are provided by the user (). You should omit them when executing the commands.

    # Create a new branch and move to that branch
    git checkout -b <branch-name>
    
    
    
    # Move to an existing branch
    git checkout <branch-name>
    
    
    
    # Check the branch you are on and
    # List all the existing branches
    git branch
    
    
    
    # Delete a branch 
    git branch -D <name-of-the-branch-to-delete>
    
    
    
    # Merge code from another branch into a current branch
    git merge <branch-from-which-to-merge>
    
    
    # List the created commits on the current branch
    git log

Additional Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment