Tag Archives: NodeJS

Back to blog home page

Deeper Mandrill integration using AWS Lambda

Posted by on Mar 21, 2017

Mandrill is a transactional email API built by MailChimp to facilitate programmatic communications with your app’s users. While we already have some demonstration JavaScript for sending a plain message via Mandrill, supporting attachments needs a server-side Node.JS Action. Below, we’ll create a server-side Node JS action (powered by AWS Lambda) that imports the Mandrill SDK, allowing you to easily send email with attachments through Mandrill in your Backand application.

Getting Started in Backand

To get started with a Mandrill action, you’ll need to first create a new Server-Side NodeJS action in Backand. To do so, open up your app’s dashboard at https://www.backand.com, and navigate to an object that will host the action. On the Actions tab of this object, create a new “On Demand” action. Name this action, then select “Server-Side Node.JS Action” as the action’s type. Follow the documentation provided to download the Backand CLI and initialize your action locally.

Backand’s Server-Side Node.js actions are implemented as Amazon Lambda functions. These functions are built using Node.js, and deployed as you would any other Node application. Backand provides a convenient CLI for managing these actions (documented in the action description), as well as easy-to-use tools to trigger execution of the Lambda function from the REST API.

Initializing the Mandrill Action

Once you have the Server-Side Node.js action ready to go, the next step is to create an action in Mandrill. Navigate to http://www.mandrill.com/ and create a new action in the MailChimp dashboard provided when you log in. Once the action is ready, copy down the Mandrill API Key value and save it somewhere safe. This API key will be used by the Node.js action to connect and communicate with Mandrill.

Updating the Code

Next, we’ll need to update the action’s code to communicate with Mandrill. We’ll start by configuring the mandrill SDK requirements in index.js. Add these lines into index.js in your Node.js action folder structure, before the function exports.backandCallback:

Note: Be sure to replace MANDRILL_API_KEY with the value copied down from the Mandrill dashboard.

Next, we’ll modify the backandCallback function to send a message with Mandrill. Replace the contents of this function with the following code:

This code does two things:

The initial code fetches the attachment data from the server on which it is stored. If this code succeeds, it calls sendEmail with the file data provided as a Base 64 string.
sendEmail then takes this data and contacts Mandrill to send the message.

Configuring the Code

To tie the project together and finalize the above code, simply replace each of the placeholders with the appropriate value:

  • PATH_TO_ATTACHMENT_INCLUDING_FILENAME – this is the URL to the attachment you wish to send. If fetching this fails, sending the message will not succeed.
  • FILENAME_OF_ATTACHMENT – this is the file name that will be given to the attachment.
  • RECIPIENT_EMAIL – This is the email for the message’s intended recipient.
  • RECIPIENT_DISPLAY_NAME – This is the recipient’s display name.
  • SENDER – This is the email from which the message was sent.
  • EMAIL_SUBJECT – This is the subject of the email.
  • MESSAGE_BODY – This is the content of the email.

You can also use the parameters argument to the action to send additional message data, whether that data originates in your app’s database or via the API call. Once these changes are made, your server-side action is ready to deploy!

Testing and Deployment

You can debug and run the action locally using the provided debug.js file. Simply enter node debug.js on the command line to debug. Once you’ve finished your local testing, you can then deploy the action via the documentation provided in the Server-Side Action’s UI in your app’s dashboard at Backand.com – head to the Actions tab for the relevant object, and follow the instructions on using backand action deploy to deploy your code.

Calling the Action

To call the action in your client-side code, simply use the Backand SDK’s action functionality as you would any other on-demand action:

Simply replace OBJECT_NAME with the name of the object controlling your action, and ACTION_NAME with the Server-Side Node.js Action’s name in Backand. You can provide any extra information or detail using the provided parameters object – this will be passed into the parameters argument of your action.


Many apps need to send additional supporting documents along with their transactional messages, such as images used in the message or related files. With the above Server-Side Node.js Action, you’re given the full capability necessary to enhance your transactional messages with any attachments you see fit. Learn more about Backand’s Server-Side Node.js actions in the documentation, or make use of our previous example on sending messages without an attachment from a custom JavaScript action.

Back to blog home page

Making a Node.js Project into an NPM Package

Posted by on Jan 05, 2016

We recently published an NPM package, backand-hosting-s3, intended to sync a local project folder to Backand AWS S3 bucket. This bucket serves our users as a static web site for their AngularJS projects. The package is to be used in GulpJS files and in the forthcoming Backand CLI (more on this soon).
After completing development, while trying to publish the package, we encountered a few salient holes in the vast amount of guides and articles.

Below we provide some instructions on these points that will hopefully make your life easier when trying to publish an NPM package.

Continue reading

Back to blog home page

Need to Upgrade Your Enterprise App to Angular?

Posted by on Nov 04, 2014

One of the keys to success in web development lies in knowing how to best use your tools. From smaller organizations looking to get a new product off the ground to larger organizations looking to optimize internal processes, an intelligently-applied Angular application can both ease implementation cause and speed deployment. In this sample case study we’ll look at how an Angular app can save time – and resources – as a front-end to a large internal database.

Continue reading