Code Monkey home page Code Monkey logo

newsletterapi's Introduction

Newsletter Subscription Service

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.

Installation

  1. Clone the repository:

    git clone https://github.com/Gladiator-Games/newsletterapi.git
  2. Install dependencies:

    npm install
  3. 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
    

Usage

Start the server:

npm start

Endpoints

  • POST /subscribe: Allows users to subscribe to the newsletter.

    • Request body: { "email": "[email protected]" }
    • Response:
      • Success: { "success": true, "message": "Subscribed successfully", "email": "unsubscribe_url" }
      • Failure: { "success": false, "message": "Error message" }
  • GET /unsubscribe: Allows users to unsubscribe from the newsletter.

    • Query parameter: [email protected]
    • Response:
      • Success: Returns the unsubscribe confirmation page.
      • Failure: { "success": false, "message": "Error message" }

Rate Limiting

Requests to the /subscribe endpoint are limited to 5 requests per 24 hours.

Email Templates

  • Subscription confirmation email: subscribe.html
  • Unsubscribe confirmation email: unsubscribe.html

Dependencies

  • 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.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

newsletterapi's People

Contributors

sanelryan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.