Quick Start | Architecture | Authentication | Card wall | Installing | Testing | Screenshots
Makers Academy's second engineering project - A FaceBook clone.
The second of our team Engineering Projects as part of the Makers Academy software development bootcamp, over two weeks our team of 5 was tasked with understanding a pre existing codebase, using the MERN stack. MongoDB, React, Express and Cypress were all brand new technologies to us at the start of this project, and much of the time and energy over the two weeks went into learning these, and how they had been put into practice in the existing codebase.
From the Makers Academy brief:
In this project, you are tasked with working on an existing application. A significant part of the challenge will be to familiarise yourself with the codebase you've inherited, as you work to improve and extend it.
This assumes that you have Node.js and MongoDB installed on your machine. If not, see the Installing and Running the Application section below.
Environment variables are used to store the JWT secret and the MongoDB URI. Without these details you will not be able to run this app locally. You can however, set up your own MongoDB Atlas and alter the URI accordingly.
- Clone this repository to your local machine.
- Create a
.env
file in theapi
directory with the following content: - ONLY if you wish to run tests, create the MongoDB test database and its collections (the main 'acebook' DB will be created automatically when the application is used):
mongosh
use acebook_test
db.createCollection("users")
db.createCollection("posts")
- You will need two terminal windows open, one for the frontend and one for the backend.
- For the backend:
# from the root directory of the project
cd api
# to install dependencies
npm install
# to start the backend server
JWT_SECRET=SUPER_SECRET npm start
- For the frontend:
# from the root directory of the project
cd frontend
# to install dependencies
npm install
# to start the frontend server
npm start
- Your browser should open the project at
http://localhost:3000/
.
Top | The Brief | Quick Start | Authentication | Card wall | Installing | Testing | Screenshots
This application is comprised of two distinct pieces.
- A backend API built with Express
- A front end built with React
The React front end sends HTTP requests to the backend API and receives JSON in response body, rather than a whole page of HTML.
Currently, user password are stored in the DB in plaintext. In a real world implementation of this application, we would of course have used a hashing alogirithm for this (a ticket we did not get time to implement during the project).
The application uses JSON Web Tokens for authentication.
Here, we've used an environment variable called JWT_SECRET
, which you'll see used in the commands to start the application and run the tests (below). You can change the value of that environment variable to anything you like.
Our team trello board shows the tickets we worked through, and what was still in our backlog at the end of the final sprint.
Team trello board 2 | Team trello board 3 |
---|---|
Top | The Brief | Quick Start | Architecture | Authentication | Card wall | Installing | Testing | Screenshots
For Mac:
- Install Node Version Manager (NVM)
Then follow the instructions to update your
brew install nvm
~/.bash_profile
. - Open a new terminal
- Install the latest version of Node.js, currently
18.1.0
.nvm install 18
For other operating systems, see the Node.js website.
- Install MongoDB:
brew tap mongodb/brew
brew install [email protected]
Note: If you see a message that says If you need to have [email protected] first in your PATH, run:
, follow the instruction. Restart your terminal after this.
2. Start MongoDB
brew services start [email protected]
- Create the MongoDB test database and its collections (the main 'acebook' DB will be created automatically when the application is used):
mongosh
use acebook_test
db.createCollection("users")
db.createCollection("posts")
- Clone this repository to your local machine.
- cd into the project directory. You will need two terminal windows open, one for the frontend and one for the backend.
- For the backend: Note the use of an environment variable for the JWT secret
# from the root directory of the project
cd api
# to install dependencies
npm install
# to start the backend server
JWT_SECRET=SUPER_SECRET npm start
- For the frontend:
# from the root directory of the project
cd frontend
# to install dependencies
npm install
# to start the frontend server
npm start
- Your browser should open the project at
http://localhost:3000/
.
You may register as a new user with an optional avatar and then log in.
After logging in, you'll be able to create posts, like and comment.
Top | The Brief | Quick Start | Architecture | Authentication | Card wall | Installing | Screenshots
Note the use of an environment variable for the JWT secret
Start the server in test mode (so that it connects to the test DB)
cd api
JWT_SECRET=SUPER_SECRET npm run start:test
Then run the tests in a new terminal session:
cd api
JWT_SECRET=SUPER_SECRET npm run test
Note the use of an environment variable for the JWT secret
Start the backend server in test mode as per above
Set the environment variable that allows Cypress to conect to your MongoDB instance running locally by copying the address of the server on which MongoDB is running e.g. 'mongodb://localhost:27017', and running the command export MONGO_URI=[your_mongoDB_server_address]
(without the square brackets)
Then start the front end in a second terminal session:
cd frontend
JWT_SECRET=SUPER_SECRET npm start
Then, to run all Cypress tests in a new terminal session:
cd frontend
JWT_SECRET=SUPER_SECRET npm run test
To run only the Cypress component tests:
cd frontend
JWT_SECRET=SUPER_SECRET npm run test:unit
To run only the Cypress end to end tests:
cd frontend
JWT_SECRET=SUPER_SECRET npm run test:feature
Top | The Brief | Quick Start | Architecture | Authentication | Card wall | Installing | Testing
Register a new user:
Log in:
main page with posts:
Create a post:
View the added post:
Make a comment:
View the comment:
Top | The Brief | Quick Start | Architecture | Authentication | Card wall | Installing | Testing