r/reactjs • • Jun 22 '20

Show /r/reactjs Instagram using MERN stack

824 Upvotes

80 comments sorted by

48

u/[deleted] Jun 22 '20 edited Jun 23 '20

Hi guys, I made this instagram clone using MERN stack.

The frontend is built with React and React router and the backend is built using Express and Mongoose.

For styling I am using styled components and the toast notification is handled by react-toastify.

I am using react Context API for global state.

check it out πŸ‘‰ https://instaclone2.netlify.app

Github Repos:

Frontend πŸ‘‰ https://github.com/manikandanraji/instaclone-frontend

Backend πŸ‘‰ https://github.com/manikandanraji/instaclone-backend

7

u/BlackShadowv Jun 22 '20

Where did you host the backend & database?

16

u/[deleted] Jun 22 '20

The backend is hosted on heroku and for the database I am using mongodb atlas

3

u/Goldman- Jun 22 '20

Your backend server is on the free dynamo on Heroku? Does this mean that it works 24/7 just with initial "lag" as the dynamo starts after hiatus?

I'm looking for such a place to host my portfolio app's backends. Did you use some tutorial for it by any chance that I could look into?

3

u/[deleted] Jun 22 '20

yep, you are right. you can refer this article for how to deploy https://devcenter.heroku.com/articles/git.

Here's how I deployed https://github.com/manikandanraji/instaclone-backend#deploying-the-backend-to-heroku

4

u/[deleted] Jun 23 '20

Use render.com, you’ll thank me later

2

u/_Invictuz Jun 22 '20

React app hosted on heroku as well?

2

u/[deleted] Jun 23 '20

it's hosted on netlify, but you can also host it on heroku as well

1

u/_Invictuz Jun 23 '20

Ah thanks! Did you host it in netlify just to try it out or is there a specific benefit? Just trying to decide for my own MERN app.

3

u/[deleted] Jun 23 '20 edited Jun 23 '20

I used all my free hosting on heroku, so I am using netlify here. Also, netlfiy service is so easy to use

1

u/jamesbishopsreddit Jun 22 '20

Your github is awesome! How did you learn React? Did you take any courses ?

6

u/[deleted] Jun 22 '20

thanks. I took wes bos react courses initially for learning the basics and docs

3

u/IAmRC1 Jun 22 '20

This is soo amazing

87

u/T4pZ Jun 22 '20

You should remove the .env from your backend repo and put it in the .gitignore

14

u/[deleted] Jun 22 '20

thanks man

0

u/[deleted] Jun 22 '20

[deleted]

29

u/[deleted] Jun 22 '20

just now changed it, thanks for the heads up

-22

u/cjthomp Jun 22 '20 edited Jun 23 '20

Edit: fine

20

u/nahoskins Jun 22 '20

You're a bit of a dick.

12

u/dschazam Jun 22 '20

batmanisawesome

9

u/[deleted] Jun 22 '20

no, he is not.

47

u/trent1024 Jun 22 '20

Even if you do that you can still find the file in your Git history. He needs to remove the file from Git completely.

0

u/[deleted] Jun 22 '20

[deleted]

16

u/gunnnnii Jun 22 '20

I usually push a .env_example, rather than just .env, in that case, since I don't want to put anyone else at risk of pushing their file.

1

u/[deleted] Jun 23 '20

[removed] β€” view removed comment

4

u/T4pZ Jun 23 '20

You have configurations for local dev and production. Not everyone needs to know the production secrets.

The secrets of your app, like production DB password or connection, should be in environment variables on the machine that runs your app.

He is hosting on Heroku so you can use Heroku config vars

Docker compose has env File support.

If you have lots of secrets that you share between apps look at https://www.vaultproject.io/ or Spring config server.

7

u/[deleted] Jun 22 '20

on fronted side there are a lot of repeated DRY code in api.js, i suggest, use axios interceptors to handle token, and to use react-query,
I liked it is simple but nice

4

u/[deleted] Jun 22 '20

I also felt it could be improved when writing those, will definitely look into interceptors for handling tokens, thanks.

4

u/Irantwomiles Jun 22 '20

What was your experience using the Context Hook as apposed to Redux?

7

u/[deleted] Jun 22 '20

I don't have much experience using redux apart from reading the docs and building a toy project. But I love using context api as it is simple and easy to reason about.

2

u/Irantwomiles Jun 22 '20

I've been using context api recently and its very straight forward, but its giving me this feeling that maybe its too easy to use and its giving me this weird (good weird) feeling. Are there any issues that you came across while using it?

3

u/[deleted] Jun 22 '20

nope man, I didn't encoutered with it while building this clone.

2

u/mips-404-andi Jun 22 '20

How did you get the assets so perfect?

Like the send icon and igtv icon.

7

u/[deleted] Jun 22 '20

instagram -> developer tools -> copy element svg

1

u/mips-404-andi Jun 22 '20

Ah, but is there any way to do it legally? I thought insta didn't like you just copy pasting? I mean not like anyone is gonna know what you did here.

We were doing a project at work where we wanted to use the official insta play and video logos but since we are making money we can't exactly copy paste it.

1

u/[deleted] Jun 22 '20

good to know about this. For some of my other projects, I used this site for svgs https://iconmonstr.com/

β€’

u/swyx Jun 22 '20

nice work! similar project posted 3 days ago https://www.reddit.com/r/reactjs/comments/hbryhy/i_made_an_instagram_clone/

would be cool if someone wanted to go thru and compare and contrast approaches! differential analysis is where we really level up.

6

u/zuraw2006 Jun 22 '20

Nice job!

5

u/[deleted] Jun 22 '20

Looks super tight, nice job.

1

u/Daebak404 Jun 22 '20

Woah! Looks great! How long did it take for you to complete the entire project?

4

u/[deleted] Jun 22 '20

It took me about a week. I already built a similar clone using prisma and graphql, so that experience accelerated building the backend part.

3

u/JudoboyWalex Jun 22 '20

Built this in a week? Part time? That's impressive! How long you been coding?

7

u/[deleted] Jun 22 '20

As I mentioned in the comment, I built another clone (twitter) with the same functionality which helped me to build the backend a lot quicker. I have been learning coding for 12-14 months I would say.

2

u/hungtro96 Jun 22 '20

Looks neat, I suggest you can create one wrapper function for API call as it was lots of duplicate logic in there. You can check this blog post for more information: https://kentcdodds.com/blog/replace-axios-with-a-simple-custom-fetch-wrapper

Anyways, nice work, keep it up!

1

u/[deleted] Jun 22 '20

thanks for your suggestion, the api file definitely needs some cleanup

1

u/[deleted] Jun 24 '20

Hey, I just want to thank you for recommeding that article, now I completely replaced axios with fetch and the api calls now looks much better. Thanks, once again.

1

u/digitalbiz Jun 22 '20

Mind sharing a GitHub repo?

1

u/dohaboha Jun 22 '20

woah!!! How long how did it take for you to reach at this level!!?

2

u/[deleted] Jun 22 '20

I have been learning web dev and programming for 12-14 months. I took courses, watched youtube vids and built toy projects along the way

2

u/dohaboha Jun 22 '20

Part time or full time???! Just curious. I have been studying everyday in and off after work for about 2 years and still dream of reaching your level man!! Did you try any luck with jobs??'

1

u/Fire_Lord_Zukko Jun 23 '20

I saw someone else asked, but I'm very curious, any luck yet with getting a job?

1

u/[deleted] Jun 23 '20

I am doing my bachelors right now (final sem examinations are postponed). after that, I will start applying for jobs.

1

u/Absorber1 Jun 23 '20

Hey can u give link for this instagram app to clone ?

1

u/kex_ari Jun 23 '20

I’m curious about your image hosting. What happens if someone uploads illegal content? Are you liable?

1

u/[deleted] Jun 23 '20

not sure what will happen, already lots of disturbing images people have been posted, I am manually deleting it

1

u/KremBanan Aug 01 '20

Hey man cool stuff, what tutorials did you use? Especially for the folder structure on client and backend? I've seen many people do it like this, any good tutorials or repos you watched?

1

u/[deleted] Aug 01 '20 edited Aug 01 '20

frontend: I think in redux documentation they uses this style, I picked it when I was watching a youtube video about redux

backend: for the backend I used brad traversy udemy course where he builds an api using this structure

3

u/sadsloth97 Jun 23 '20

Looks awesome! Not sure if NoSQL would be my top choice for a social network - it’s all relational data!

2

u/abhishekkhaiwale Jun 23 '20

nice work , even i have just started with the learning process and this clone is motivating me even more to dive deep into react.

1

u/ShovonX Jun 22 '20

The post modal has issues. If you upload an image that is a bit long the caption input gets hidden below, and it's not scrollable either.

Happens to portrait, don't give the height to 100%.

2

u/[deleted] Jun 22 '20 edited Jun 22 '20

Will fix it when I have some time, thanks for checking it out

1

u/anna_umi Jun 22 '20

Looks cool 😎

1

u/david340804 Jun 22 '20

This is clean! Great work!

1

u/sultan1640 Jun 22 '20

This is awesome. Keep the good works up.

1

u/The_Noah_Blitz Jun 22 '20

Excellent work!

1

u/NiceWetTissue Jun 24 '20

You are fucking amazing. Every week you show off a big project.

0

u/delta_charlie_2511 Jun 23 '20

https://react12.io/instagram-clone

For anyone interested in following this tutorial

0

u/[deleted] Jun 22 '20

[deleted]

4

u/[deleted] Jun 22 '20

It took me about a week. I already built a similar clone using prisma and graphql, so that experience accelerated building the backend part.

2

u/NiceWetTissue Jun 24 '20

How many hours a day?

2

u/[deleted] Jun 25 '20 edited Jun 25 '20

pretty much full time I would say (8-10 hours)

0

u/[deleted] Jun 22 '20

[deleted]

1

u/[deleted] Jun 23 '20

I directly took it from instagram or you can try this site https://iconmonstr.com/

7

u/[deleted] Jun 22 '20

[removed] β€” view removed comment

5

u/[deleted] Jun 22 '20

yep

1

u/justSomeGuy5965 Jun 23 '20

Ok now you've got me curious. What is whiplash?

4

u/[deleted] Jun 23 '20

It's an amazing movie, here's the summary 'A promising young drummer enrolls at a cut-throat music conservatory where his dreams of greatness are mentored by an instructor who will stop at nothing to realize a student's potential.'

You should watch it https://www.imdb.com/title/tt2582802/

2

u/justSomeGuy5965 Jun 23 '20

Woah looks like a wild ride!