The below steps should be done only once your project idea was verified by your captain and you have your documentation/README completed.
Create the project locally using express-generator
.
Run the express-generator
command below and specify the name of the project:
npx express-generator --view=hbs your-project-name
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 during your future projects which may contain API keys, session secrets, etc.
Create the .env
file in the root folder of the project.
touch .env
In the .env
file add the following variables, but remember to update the MONGODB_URI
part saying your-db-name
, where you should put the name of your database :
PORT=3000
MONGODB_URI=mongodb://localhost:27017/your-db-name
SESSION_SECRET=ADD-A-RANDOM-STRING
Add the README.md
file with the finished project documentation to the root directory of the project.
- From the root folder of the project run the following commands to initialize git.
git init
git add .
git commit -m 'Initial commit'
-
Open GitHub and create a new repository for your project.
-
Copy the
git remote add origin ...
command from the GitHub setup instructions and run it locally from the terminal.
-
After you are done with the above step, push the initial commit and the
master
branch to GitHub:
git push origin master
Your local repository and your GitHub repository are now successfully connected!
Next step is 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
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:
- Open the Settings tab.
- In the left-hand side menu select Manage access.
- Click on the button Invite a collaborator.
- Search for and add the other team member by the GitHub username or email.
- The other team member must accept the invitation (either by email that is automatically sent, or by the invitation link).
After the project/repository owner does the above steps and pushes the new develop
branch and the updates to GitHub, the other team member/s should clone the repository and pull all the branches.
In the below example the angle brackets
< >
indicate the identifier/parameter/argument values that are provided by the user. You should omit them when executing the commands.
git clone <url-of-the-project-repo>
Once cloned the team member/s should navigate to the root directory of the cloned project and run the following command to pull the develop
branch, will download the develop
branch and make it available locally for the other teammember :
git pull origin develop
-
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 be preferably done in pair, taking turns while coding and preferably coding on one laptop (pair programming).
- Do daily 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'
inroutes/auth.js
"
- "Add session middleware to
In the below example 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