Skip to content
An example of a NodeJS application that processes all existing and incoming email messages in connected accounts.
JavaScript HTML
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
routes Properly associate EmailMessages with UserIds Oct 13, 2016
src Switch to rpush for correct FIFO queue Oct 13, 2016
views Expand example, focus on processing all mail Oct 13, 2016
.gitignore update gitignore, add config template Oct 14, 2016
config.js.template update gitignore, add config template Oct 14, 2016
package.json Expand example, focus on processing all mail Oct 13, 2016
web.js add callback url for auth, fix typo Oct 14, 2016
worker.js Small fix for missing userId Oct 13, 2016

Nylas Sync Example

This example demonstrates how to process all mail in your user's email accounts, creating a cache of the messages in an application database and processing each message as it is ingested.

When an email account is linked via the example web service, a task is queued which starts pagination through all of the messages available via the Nylas API. The web service responds to the Nylas Webhooks API to process messages that are synced or received after the initial pagination. This ensures that every message in the email account is seen and processed.

This example also demonstrates how to use Redis to queue work, rather than processing it on the fly as it is received. The fetching and processing of mail is separated from the web service which responds to webhooks, so the two can be scaled separately. In production, you might consider using another queue service, like Amazon SQS, and using the number of items in the queue as a scaling trigger for the worker pool.



Using the Nylas Webhooks API requires that Nylas is able to reach your machine to send a webhook. To make testing easy, this example uses ngrok.

NodeJS / NPM

Make sure node and npm are installed. This example requires Node 4.0 or greater and uses ES2016 JavaScript syntax.


This example uses Redis as a simple queue service. In production, you might consider using ActiveMQ or Amazon Simple Queue Service (SQS). To install redis on Mac OS X, run brew install redis.

Getting Started

  1. Install Dependencies:
npm install
  1. Place your Nylas App ID and Secret in config.js

  2. Start a Redis server by running redis-server at a command prompt.

  3. Start ngrok by running ngrok http 1234 at a command prompt.


In two separate terminals, launch the web service and a sync worker. You can run multiple sync workers if you'd like - they pull tasks from the Redis queue:

npm run web
npm run worker

Follow the instructions that are printed to the console by the web service. To see the example in action, you'll need to link an account by visiting http://localhost:1234/

Once you've linked an account, you'll see database.sqlite begin to fill with email messages, with the subject prefixed with "PROCESSED:".

You can’t perform that action at this time.