A Node.js application that allows users to create, edit, view, and delete their blogs. The app ensures data security and user authentication using JWT. Admin-level permissions enable enhanced control over user-generated content.
- Features
- Technologies Used
- Prerequisites
- Installation
- Environment Variables
- Usage
- API Endpoints
- License
- User Authentication: Secure login and registration using JWT.
- CRUD Operations:
- Users can create, edit, view, and delete their own blogs.
- Admins can manage all users' blogs.
- Security Measures:
- Implements security headers using helmet.
- Rate limiting via express-rate-limiter.
- Database Flexibility: Uses MongoDB for data storage.
- Node.js
- Express.js
- MongoDB (via mongoose)
- JWT
- bcrypt.js
- axios
- helmet
- express-rate-limit
Ensure you have the following installed:
- Node.js (v14 or higher)
- MongoDB (local or hosted)
- npm (comes with Node.js)
-
Clone the repository:
git clone https://github.com/kxng0109/blog-app.git cd blog-app
-
Install dependencies:
npm install
-
Set up environment variables (see Environment Variables).
-
Start the server:
npm start
Create a .env file in the root directory with the following variables:
PORT=3000
MONGO_URI=<link_to_mongodb_database>
JWT_SECRET=<your_jwt_secret>
Replace <link_to_mongodb_database> with the path to your mongoDB database Replace <your_jwt_secret> with a secure secret key for JWT. Note: Never push your .env file to version control.
- Start the server:
npm start
- Access the application via:
http://localhost:PORT
Note: "PORT" is set to 3000 by default.
- Use tools like Postman to test API endpoints.
- POST /app/register: Register a new user with name, email and password.
- POST /app/login: Login with email and password.
- GET
/app/blog/
: Fetch all blogs. - GET
/app/blogs/:id
: Fetch a single blog by ID. - GET
/app/blog/personal/
: Fetch your own blogs - POST
/app/blogs
: Create a new blog. - PATCH
/app/blogs/:id
: Update a blog by ID. - DELETE
/app/blogs/:id
: Delete a blog by ID. Note: Authentication is required for all endpoints.
This project is licensed under the MIT License - see the LICENSE file for details.