Building a Reddit clone using the popular MERN (Mongo – Express – React – Node) stack.
git clone
this repo- Install all dependencies for both the front-end and back-end
- Make sure MongoDB is running (
mongod
), then start your Node and React servers- Back-end and front-end servers should be running on separate ports, in separate Terminal tabs
- Ensure both servers are up and running by visiting their existing endpoints in your browser
- Take a look around:
- BACK-END: What routes, models, and controllers have been set up? What kind of database is it connecting to?
- FRONT-END: What components have been set up?
- Install
nodemon
and change yournpm start
for the back-end to runnodemon server.js
- Create a
TextPost
model that containstitle
,content
,thumbnail_image_url
,votes
,comments
(comments
should be an array of (embedded)[https://github.com/SF-WDI-LABS/mongoose-associations]Comment
models) - Add the following API CRUD routes for
Posts
/api/posts
– GET, POST/api/posts/:post_id
– GET, PUT, DELETE
- Fill out the
Posts
controller using Mongoose queries – good review / reference here - Add to your
seed.js
file to create aPost
– verify that it shows up at the appropriate endpoint - Use POSTMAN to confirm that the other CRUD routes are working as well (PUT, DELETE)
- Create a
Comment
model that containscontent
,votes
- Add the following API CRUD routes for
Comments
/api/posts/:post_id/comments
– POST/api/posts/:post_id/comments/:comment_id
– GET, PUT, DELETE
- Fill out the
Comments
controller using Mongoose queries - Add to your
seed.js
file to create aComment
, attached to aPost
you've created – verify that it shows up at the appropriate endpoint - Use POSTMAN to confirm that the other CRUD routes are working as well (PUT, DELETE)
- Use POSTMAN to create two
Post
s - Use POSTMAN to create two
Comment
s, both attached to the firstPost
you created - Populate the
seed.js
file to automate data seeding
- Go to your React app's homepage – poke around the
src/
directory to make sure you know why the UI is showing up as it is - Pull in react-router-dom to implement the following routes – just put in some dummy text to confirm your React routes are working, before implementing full functionality:
/
routes to home page (/pages/HomePage.js
). Displays all my posts' titles, their thumbnail images, and their votes count./posts/:post_id
routes to eachTextPost
's show page (/pages/SinglePostPage.js
). Displays that post's content, attached comments, and form for adding comments (implement comments & form later)
- Think about what will live in the state for each page – each page is basically a container, like
<Twitter/>
andTodosContainer
<HomePage/>
will probably store all posts in its state, like we storedthis.state = { allTweets: [] }
in<Twitter/>
, orthis.state = { allTodos: [] }
in<TodosContainer/>
=<SinglePostPage/>
will probably have all the details for a post in its state
- Think about what components each page will contain
- What API requests will each page make
- Think about the HTTP request library you'd like to use to fetch data from your Node API endpointments (e.g.
$.ajax
,fetch
,axios
, etc.). I recommendfetch
because it is available to you without installing any dependencies. It is also widely accepted as the go-to AJAX call library to use with React.
Fetch documentation here; great reference material here.
Fetch GET request:
fetch('http://localhost:8080/api/posts').then((res) => {
return res.json();
}).then((json) => {
// do stuff with the JSON you get back here
console.log(json);
});
Fetch POST request:
fetch('http://localhost:8080/api/posts', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
title: 'my new post title',
content: 'my new post content',
thumbnail_image_url: 'some_url',
votes: 3,
comments: []
})
}).then((res) => {
return res.json()
}).then((json) => {
// do stuff with the JSON you get back here
console.log(json)
});
- User should see all posts on the home page (BONUS: rank them in descending order by
votes
) - User should be able to click on a "Create Post" button and see a modal or navigate to a new page to create a new
Post
- User should be able to vote on a post
- User should be able to create a
Comment
on aPost
- User should be able to vote on a
Comment
- User should be able to comment on a comment (requires changing the
Comment
model's schema)
- Create a
LinkPost
resource- Another kind of post a Reddit user can upload (simply links to an external link, e.g. news article or imgur page)
- Model should contain fields
title
,link_url
,thumbnail_image_url
,votes
, - Can also leave
Comment
s on aLinkPost
- Create a
User
resource- Model should contain fields
first_name
,last_name
,email
, andpassword_hash
- Implement authentication
- Both
Post
andComment
should haveauthor_id
(views should include author names)
- Model should contain fields
- Implement a
SubReddit
model- Should have
name
andslug
(e.g. 'Software Engineering', 'software-engineering') Post
should have asubreddit_id
- There should be a React route for going to subreddit routes (e.g.
/r/software-engineering
)
- Should have