🚀 🔥 A RESTful API for blogging platform that allows users to create, read, update and delete (CRUD) 📕📗📘📙 blogs, The API also support user authentication and authorization, allowing users to create and manage their own blog.
https://documenter.getpostman.com/view/24272627/2s93m1aPuo
-
Secure your API using 🔒 Helmet and 🛡️ Express Mongo Sanitize.
-
Optimize and improve API performance using 🚀 PM2 process manager.
-
Scale your API by creating a cluster with PM2. 🌐
To run the API, make sure you have the following installed on your system:
-
🟢 Node.js (version X.X.X)
-
🍃 MongoDB (version X.X.X)
-
Clone the repository:
git clone git@github.com:MeetMuaz/backend-assessment.git
-
Navigate to the project directory:
cd backend-assessment
-
Install the dependencies:
npm install
-
Create a
.env
file in the root directory and provide the necessary environment variables:PORT=3000 MONGO_URI=mongodb://localhost:27017/blog JWT_SECRET=your_secret_key
Replace the values with your desired configuration.
-
Start the API:
npm start
This will start the API server at
http://localhost:3000
.
This API uses the following security measures:
-
Helmet: Helmet helps secure your Express.js application by setting various HTTP headers. It provides protection against common security vulnerabilities.
-
Express Mongo Sanitize: Express Mongo Sanitize helps prevent NoSQL injection attacks by sanitizing user-supplied data before interacting with the MongoDB database.
PM2 is a process manager for Node.js applications that helps optimize performance and manage application processes. To start the API with PM2, follow these steps:
-
Install PM2 globally (if not already installed):
npm install -g pm2
-
Start the API with PM2:
pm2 start app.js --name blogging-api
This will start the API using PM2 and assign it the name
blogging-api
. -
Monitor API logs:
pm2 logs blogging-api
Use this command to monitor the logs and troubleshoot any issues.
To improve performance and scalability, you can create a cluster with PM2 to run multiple instances of the API. Follow these steps:
-
Stop the existing API process (if running):
pm2 stop blogging-api
-
Create a cluster of API instances:
pm2 start app.js -i <num_instances> --name blogging-api
Replace
<num_instances>
with the desired number of instances to run in the cluster. -
Monitor the cluster:
pm2 monit blogging-api
Use this command to monitor the cluster and view resource usage.