This is a simple Express-based app that includes user authentication, authorization, and file upload functionality. It uses bcrypt
for password hashing, jsonwebtoken (JWT)
for secure token generation, and cookies for storing the JWT. Once logged in, users can create, view, edit, and like posts, as well as upload profile picture.
- User Authentication: Login with a username and password.
- User Authorization: Only logged-in users can access post-related actions (view, create, edit, and like posts).
- Post Management: Users can create new posts, view existing ones, edit posts they created, and like posts.
- File Uploads: Users can upload profile picture using
multer
.
- Express.js: Web framework for Node.js
- bcrypt.js: For hashing and comparing passwords
- jsonwebtoken (JWT): For generating secure tokens to handle user authentication
- Cookies: For storing and verifying JWT on the client side
- MongoDB: Database to store user data and posts (or any other database of your choice)
- multer: Middleware for handling file uploads
- Node.js installed (version 14.x or higher)
- MongoDB instance (locally or via MongoDB Atlas) for storing users and posts
- Clone the repository:
git clone https://github.com/likhithkp/express-posts.git cd express-posts
- Install dependencies:
yarn
- Start the server:
yarn dev
- Registration: Users can register with their username and password. The password is hashed using bcrypt before being stored in the database.
- Login: Upon successful login, a JWT is generated and sent to the client. This token should be stored securely (e.g., in cookies).
- Authorization: For any post-related actions (like viewing, creating, editing, or liking a post), the client must send the JWT in the Authorization header to authenticate the user.
- Post Management: Users can create, view, edit, and like posts. Only the user who created a post can edit or delete it.
- File Uploads: Users can upload profile picture. The files are stored and retrieved using multer middleware.