npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

contentful-sync-redis

v0.4.1

Published

Keep an up-to-date copy of your Contentful space in Redis

Readme

Build Status

contentful-sync-redis

Keep an up-to-date copy of your Contentful space in Redis

What does this package do?

  • Keeps a copy of your Contentful space in Redis, using the Contentful Sync API.
  • Provides a helper function to resolve Links inside your entries.

Why wouldn't I use the Contentful Javascript SDK?

The Contentful JS SDK is a only thin wrapper on top of their API, and it can be tedious to implement the Sync API in every project.

Install

npm install --save contentful-sync-redis

Usage

const ContentfulSyncRedis = require('contentful-sync-redis')
const cf = new ContentfulSyncRedis({ space: 'space_id', token: 'access_token' })
cf.getEntries()
	.then(entries => yourFunction(entries))

API

Initialisation

Initialise the module using the new operator, passing in the mandatory values for:

  • Contentful space ID
  • Contentful access token

Optionally, also pass in:

  • Contentful API host
    • Default: cdn.contentful.com
  • Redis URL
    • Default: redis://localhost:6379
const ContentfulSyncRedis = require('contentful-sync-redis')
const cf = new ContentfulSyncRedis({
	space: 'string',
	token: 'string',
	contentfulHost: 'optionalString',
	redisHost: 'optionalString',
})

Synchronisation

Perform the initial download of content to Redis - it's often worth calling this just after initialisation

cf.sync() // returns an empty promise

Getting Entries

Return all entries in the Contentful space, after making sure the cache is synced.

You can use this without calling sync() beforehand.

cf.getEntries() // returns a promise containing the entries

Get Entries and Resolve Links

A wrapper function that calls getEntries and then resolveReferences.

cf.getResolvedEntries(entries) // returns a promise containing the resolved entries

Resolving Links

Dereferences links to other entries in your content and groups fields by locale. Pass in an array of entries.

cf.resolveReferences(entries) // returns a promise containing the resolved entries

e.g.

cf.resolveReferences([
	{
	  sys: { ... },
	  fields: {
	    title: {
	      "en-US": `Home`,
	    },
	    summary: {
	      "en-US": `This is the homepage, it talks about the site `,
	    },
	    sections: {
	      "en-US": [
	        {
	          sys: {
	            type: `Link`,
	            linkType: `Entry`,
	            id: `6Gz0vGZmAoSgOSAM2Ks4gW`,
	          },
	        },
	        {
	          sys: {
	            type: `Link`,
	            linkType: `Entry`,
	            id: `S9n6QORFyEeKEUaGS2Ym4`,
	          },
	        },
	      ],
	    },
	  },
	}
])

Returns a Promise which resolves to:

{
  sys: { ... },
  fields: {
    "en-US": {
      title: `Home`,
      summary: `This is the homepage, it talks about the site `,
      sections: [
        {
          sys: { ... },
          fields: {
            "en-US": {
              title: `About us`,
              content: `Made by Matt Dean`,
            },
          },
        },
        {
          sys: { ... },
          fields: {
            "en-US": {
              title: `Introduction`,
              content: `Hi this is contentful-sync-redis`,
            },
          },
        },
      ],
    },
  },
}

Where 'sections' is a multi-reference field

Logging

See the debug module. Use the package name (contentful-sync-redis) as the string in the environment variable.

Release Map / Changelog

MVP - 0.1

  • [x] Implement Sync API
  • [x] resolveReferences helper function
  • [x] Preview API supported

0.2

  • [x] Tests using Mocha
  • [x] CI integration using Travis
  • [x] Contribution guidelines

0.3

  • [x] Group fields by locale
  • [x] No longer configure Redis client using an environment variable

0.4

  • [x] Add sugar function to get entries and resolve references with a single call

1.0

  • [ ] Support old versions of Node using webpack

Later releases / To do

  • Plugin functionality to allow for other databases
  • Support filtering content
  • Support assets

Contributions

All contributions welcome! Please feel free to open an issue/PR :smile: