Created by Sanel Ryan @ Gladiator Games
This is a Node.js application for managing newsletter subscriptions and unsubscribes. It utilizes Express.js for handling HTTP requests, MongoDB for data storage, Nodemailer for sending emails, and Express Rate Limit for limiting the number of requests.
-
Clone the repository:
git clone https://github.com/Gladiator-Games/newsletterapi.git
-
Install dependencies:
npm install
-
Set up environment variables by creating a
.env
file in the root directory and adding the following variables:EMAIL_HOST=your_email_host EMAIL_PORT=your_email_port EMAIL_USER=your_email_user EMAIL_PASS=your_email_password URI=your_mongodb_uri FROM_EMAIL=your_from_email_address PORT=desired_port_number COMPANY_NAME=your_company_name
Start the server:
npm start
-
POST /subscribe
: Allows users to subscribe to the newsletter.- Request body:
{ "email": "user@example.com" }
- Response:
- Success:
{ "success": true, "message": "Subscribed successfully", "email": "unsubscribe_url" }
- Failure:
{ "success": false, "message": "Error message" }
- Success:
- Request body:
-
GET /unsubscribe
: Allows users to unsubscribe from the newsletter.- Query parameter:
email=user@example.com
- Response:
- Success: Returns the unsubscribe confirmation page.
- Failure:
{ "success": false, "message": "Error message" }
- Query parameter:
Requests to the /subscribe
endpoint are limited to 5 requests per 24 hours.
- Subscription confirmation email:
subscribe.html
- Unsubscribe confirmation email:
unsubscribe.html
express
: Fast, unopinionated, minimalist web framework for Node.js.mongodb
: The official MongoDB driver for Node.js.nodemailer
: Module for sending emails.express-rate-limit
: Basic rate-limiting middleware for Express.
Contributions are welcome! Please open an issue or submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.