Instructions to get started with projects
- Creating Repositories
- Express Scaffolding
- React Scaffolding
- Full Stack App Scaffolding
- Git Collaboration
Creating your repositories step by step
- On your GitHub page, select the
+
sign in the top right corner, and selectNew repository
- Choose your project name (ideally in lower case)
- Make this private (you can change it to public later on)
- Initialize with a README if you haven’t already created one locally
- Select
Create Repository
- Invite your instructor as a collaborator
- Clone file as usual and start working!
Express Scaffolding Step by Step
- In your project repository on the terminal, run
npx express-generator
to scaffold the Express application - Open the folder in VSCode and remove the
/views
folder (we don’t use it) - Remove the view engine setup in app.js file (lines 12-14), because we’re not using any backend template renderers
- Change
res.render('error')
; tores.send('error')
; (again, we’re not rendering anything from the backend, we’re just sending responses back to the client) - Install packages that you may use, such as MySQL, Nodemon, or Dotenv:
npm install mysql nodemon dotenv
- In file
package.json
, remove jade from the dependencies list - Install dependencies with
npm install
oryarn
- Copy the model folder from your previous projects. This contains the
helper.js
(which contains a nice wrapper around DB connections, so we can use the db() function from within our code), and it also contains thedatabase.js
file, which is the migration file for our project (you will need to modify this file so it contains YOUR database tables definitions and dummy data) - Add a new script into your
<package.json>
file, that we will use to run our migrations:"migrate": "node model/database.js"
. Eventually, when you want to run migrations, you will need to runnpm run migrate
oryarn migrate
- Modify the start script so it uses nodemon instead of node:
"start": "nodemon ./bin/www"
- In the file
./bin/www
, change the default port to5000
(around line 15) - If you need to store private data and passwords (such as your DB pass), create a
<.env>
file in the Express project root. - Add a
.gitignore
file to your project. It should contain at least yournode_modules
and your.env
file:/node_modules
.env
- Happy coding!
React Scaffolding Step by Step
- Create React app with
npx create-react-app my-app
. (Changemy-app
to the name of your app, e.g.npx create-react-app emefa-mvp
. - In VSCode, in
src
folder, delete theApp.test.js
,serviceWorker.js
,setupTests.js
andlogo.svg
files. - In
index.js
, remove serviceWorker setup (lines 9-12), and the import from line 5. - In
App.css
remove the default styling, but keep the file for if you will use some css styling later. - In
App.js
, remove the logo import in line 2, and the header content in lines 8 - 21. - Change the functional component into class component, so you can add some state later on.
- If creating a front-end only app, simply navigate into your app folder (
cd folder-name
) andyarn start
to run the app and begin coding - If building a full-stack app, continue with the steps below
Full Stack App Step by Step
- Scaffold Express as above, and React steps 1-6
- In
package.json
in your React app, add a proxy for the back end in line 34;"proxy": "http://localhost:5000"
. - Back in the terminal, inside your React app, run
rm -rf .git
to avoid the folder being pushed to GitHub as a sub-module of your main repo. - In your Express app, create a new folder named
client
, and copy all the contents of your React app into this folder. - You have a full stack app! Happy coding!
Git Collaboration Steps
Option 1: Forks
- Fork the repo
- Clone it
- In your terminal, run
git remote add upstream [url]
(original url) - Still in the terminal, run
git checkout -b staging
You will only need to do the first 4 steps the first time you clone the repo
The following steps are for your daily workflow:
Each time you need to work on some new stuff, make sure you pull latest things from upstream: This brings you up to date with the most recent version of the project. Run the following in your terminal
-
git pull --rebase staging
(if there are merge errors, you will need to resolve them manually in VSCode before continuing. Always read the error message :) )Work on your stuff locally, then:
-
git add .
-
git commit -m "whatever"
-
git push origin staging
(You’re pushing to YOUR repository, not the upstream) -
Create a new Pull Request (PR) in staging of your repo to original repo’s staging branch
-
Repeat the cycle from 5 - 9 ;)
Option 2: Branches
- Clone the repo
- To work on a new feature, create a new branch with
git checkout -b feature-name
. Make sure you are in your main/development brach before creating the new branch. - Work on your feature
git add .
git commit -m "whatever"
git push
- Create a new Pull Request (PR) on GitHub, from your branch to the main/development branch
- Ideally, have another member of your team review that pull request. They can
git pull
andgit checkout feature-name
to review your code. - If the code is good, the PR can be accepted and merged on GH. You can optionally delete the branch after mergin (GitHub gives you that option)
- If the code needs changes, you can request them in the PR, adding comments to it. The person responsible for that PR can commit new changes into their branch, which will be added automatically to the PR.
- A common strategy is also to create issues on GH, and name your branches like
issue-14
, orbug-14
or similar things.