Skip to content
A simple API server for email subscription with MailChimp
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
LICENSE
README.md
index.js
package.json

README.md

A simple API server for email subscription with MailChimp

Installation

cd ./simple-mailchimp-api-server
npm i
node .

Configuration

Change the MailChimp config inside index.js

const config = {
  dc: '<dc>',
  apiKey: '<your-api-key>',
  listId: '<your-list-id>'
};

Basic Usage

curl

curl -d "email=xxx@example.com" -X POST localhost:3000/subscribe

HTML + JS

<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<body>
  <form onsubmit="subscribe()">
    <input id="sub-email" type="email" required>
    <button type="submit">Subscribe</button>
  </form>
  <script>
    function subcribe() {
      const email = document.getElementById('sub-email').value;
      const data = {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json; charset=utf-8'
        },
        body: JSON.stringify({ email })
      };
      fetch('http://localhost:3000/subscribe', data).then(() => {
        // Do Something here
      });
      return false;
    }
  </script>
</body>
</html>

License

ISC

Author

github/auphone

You can’t perform that action at this time.