0

How to Create and integrate MailChimp Subscribe list with Node js

In this post I might want to demonstrate to you a straightforward demo application which is expand on top of express js structure, By taking after this instructional exercise you going to fabricate a subscribe shape, through this frame client can subscribe to MailChimp subscription list.

Let’s setup your express js application by creating package.json file and install required dependency libraries by issuing below commands.

Download link : Download Source code

package.json

By issuing the above commands you have installed dependencies and created you launch file called index.js. Now open index.js in your text editor and copy past the below code into it.

index.js

Server setup is ready, now issue below commands form command line to start HTTP server.

Then head over to http://localhost:8080, you will get Hello World! text on the browser screen.

Then copy below template markup to email-subscribe.pug.

views/email-subscribe.pug

Then import pug into application, register pug template engine with middleware and render above created template for home page.

Now run the application

Integrate MailChimp

We need to generate public API key from your MailChimp account and also identify your list ID. If you are not sure how to retrieve those, follow these links from MailChimp Knowledge Base to retrieve your account’s API key and find your list ID.

Now import mailChimp library which you have installed earlier at the beginning of the application setup, update your index.js file, import mailchimp-api-v3 module and create post handler route to handle from submissions, implemented logic for subscriptions. Here is the final index.js file.

Leave a Reply

Your email address will not be published. Required fields are marked *