Solution for a challenge from Devchallenges.io.
- express generator
- bcrypt
- cookie-parser
- cors
- express
- jsonwebtoken
- mongoose
- multer
This application/site was created as a submission to a DevChallenges challenge. The challenge was to build an application to complete the given user stories.
- left many routes open - could add JWTVerifys to all routes vs just the mutate routes (post, put, delete)
- messages and channels are open - better to have a way to see the chat before signing in
- need another server (socket.io) ? to have chat group be realtime across users - don't think so - because useEffect will update the view when channels and messages change
- Promise.all() might be needed for multiple route calls in some functions - async - have to worry about order of results
- add helmet ?
- testing
- seeding the database vs using my hacky way of creating a welcome channel if it doesn't exist
- "select: false" in model vs removing field with .select('-password') vs removing field in populate call - what is best approach?
- password field may be sent back in some calls - intermediate step - password forwarded along with userInfo then removed later - should exlude first and then forward or overly concerned - password is hashed and protected by jwt
- can't pass two parameters to same route - express cant differentiate between them - need to add word in between i.e. /:channel/:id vs /:channel/id/:id
- channel controller has a very convulted route because of that and it could be cleaned up
- sorting with mongoose vs sorting response.data in the client - in React, use memo on the data.
- multer and controllers don't mix
- controllers considered an anti-pattern ?
- getting file path is difficult - fakepath issues - can't get the file to save - the folder will be created - dir name in multer middleware
- had issues with multer callback syntax - console.logs need to be inside functions inside callbacks
- Added fs unlink logic to remove photos that are no longer tied to user profiles
- Read about changes coming to Multer (2.0) so need to look out for that
- Profile pictures come from freepik. Check below for links - the majority of pictures belong to the same series.
- Added
public/uploads
to gitignore
To clone and run this application, you'll need Git and Node.js (which comes with npm) installed on your computer. From your command line:
# Clone this repository
$ git clone https://github.com/jdegand/chat-group-backend
# Install dependencies
$ npm install
# Add env variables (PORT, MONGO_URI, REFRESH_TOKEN_SECRET, ACCESS_TOKEN_SECRET) and connect to mongo
# Run the app
$ npm start
- Steps to replicate a design with only HTML and CSS
- Mafia vector created by pikisuperstar - www.freepik.com
- Cute cat vector created by catalyststuff - www.freepik.com
- 3d avatar psd created by freepik - www.freepik.com
- Github - Notezipper
- Stack Overflow - exclude password field in response
- Stack Overflow - express routes with same path but different parameters
- Stack Overflow - populate and exclude fields
- Stack Overflow - findByIdAndUpdate and arrays
- Stack Overflow - mongoose matching ids
- Stack Overflow - compare mongoose ids
- Stack Overflow - filter nested array
- Stack Overflow - mutiple query populates in single call
- Stack Overflow - mongoose sorting by createdAt
- Express Docs - multer middleware
- Stack Overflow - destination of uploaded file multer
- Stack Overflow - multer and controllers
- Stack Overflow - destination troubleshooting multer
- Stack Overflow - storing image in local folder
- Positronx - file upload tutorial with express & multer
- Stack Overflow - multer & put
- Stack Overflow - fakepath in image file name
- Stack Overflow - console.log and callback functions
- Stack Overflow - limit file size
- CodingShisha - multer validation
- Blog - node check if file exists
- Geeks for Geeks - node fs readdir method