A NextJS blog engine like no other

Meet the NextJS blog engine that integrates with your website using a straightforward API. Smooth, simple, and tasty content integration — that’s Butter.

Posted on November 16, 2023

Intuitive admin interface

So easy to use. So easy to customize. You’re going to love the blog you build with ButterCMS.

Handy integration with NextJS

Our NextJS blog engine has a simple content API and drop-in SDKs that makes the magic happen in minutes, not hours.

A truly zero-maintenance solution

With ButterCMS, you’ll never worry about security upgrades, hosting, or performance again.

You've got better things to do than build another blog

Drop our NextJS blog engine into your app, and get back to more interesting problems.

ButterCMS is an API-based blog engine that integrates seamlessly with new and existing NextJS apps. It's great for SEO, and provides a clean and modern user interface that your marketing team will love. You can deploy ButterCMS in minutes using our NextJS API client. 

That leaves plenty of time for you and your marketing team to do what you do best: create killer apps with killer content. 

Play video

See how Butter’s API enables you to launch a flexible blog with amazing SEO using your existing tech stack.

G2 crowd review award G2 crowd review award G2 crowd review award G2 crowd review award G2 crowd review award G2 crowd review award G2 crowd review award G2 crowd review award G2 crowd review award G2 crowd review award G2 crowd review award G2 crowd review award

Best blog engine on the market

headshot of Hampton Catl

After shopping the market, it was clear that ButterCMS was the perfect choice. It allows our developers to build powerful components and makes it easy for our marketing team to drive a better customer experience. Hampton Catlin Creator of Sass and Haml

Deploy our Next.JS starter in 30 seconds

Or follow the below commands to clone a copy of the repo from github, install dependencies, set your free Butter token, and run your local server on localhost:3000/.

$ git clone https://github.com/ButterCMS/nextjs-starter-buttercms.git
$ cd nextjs-starter-buttercms
$ npm install # or yarn install
$ echo 'NEXT_PUBLIC_BUTTER_CMS_API_KEY=your_free_api_token_here' >> .env
$ npm run dev # or yarn dev

Built to make content marketing easy

ButterCMS is the best NextJS blog engine for a simple reason: NextJS developers can build solutions that marketing people love. Our API allows your content gurus to quickly spin up high-converting blog templates, sidebars, related content features, and more, all using simple drag-and-drop functionality.

  • Use main domain (improves SEO)
  • Friendly admin interface
  • Upload images, video, and other media
  • Edit URL slugs and meta tags
  • Tags and categories
  • Author profiles
  • RSS/Atom feeds
  • Search
  • Webhooks
  • And more...

The simplest NextJS blog engine you'll find

Our simple setup saves you time and money. Take us for a spin to see for yourself!

headshot of LUKE GARDNER

It's the epitome of plug-and-play simplicity for content creators. It does exactly what I need it to. LUKE GARDNER, CONTENT SPECIALIST, PRINTAVO

Fast integration with any NextJS app

Our mission was to make it easy to integrate Butter with your existing NextJS app in minutes. It’s so simple! To demonstrate, here’s a mini tutorial to give you a feel for the process of adding Butter to your NextJS app.

Of course, you can also use our Pages and Collections to do advanced content modeling. For a full integration guide, check out our Official Guide for the ButterCMS NextJS API client.

Play video

See how easily you can integrate the ButterCMS Pages API with your NextJS app.

Seamless NextJS components

Empower your marketing team to create a customized blog engine that aligns perfectly with your NextJS components.

Components are the essential building blocks of any NextJS app, and ButterCMS handles them with ease.

Our drag and drop interface makes it simple to structure your content to match existing NextJS components and to create new reusable components whenever you need them.

The best NextJS blog engine for SEO

ButterCMS gives you absolute control over on-page SEO ranking factors. Key SEO variables are built into our default post template, giving your marketing team direct access to configure all of these settings, and more.

  • Page title
  • Post tags and categories
  • META description
  • URL slug
  • Featured image / Open Graph image
  • Image ALT tags
  • Link anchor text

ButterCMS saves you development time

Most customers get our NextJS blog engine up and running in less than an hour. Try it yourself!

headshot of DILLON BURNS

Simple as can be, with powerful features and great customer support. DILLON BURNS, FRONT END DEVELOPER, KEYME

How to integrate ButterCMS into your NextJS application

Integrating the Butter blog engine into your NextJS app is dead simple. Here's a mini tutorial to get a feel for setting up your blog home and blog post pages. 

For a full integration guide, check out our Official NextJS Guide

To display posts we create a new component in blog.js to fetch and list blog posts from the Butter API. See our API reference for additional options such as filtering by category or author. The response also includes some metadata we'll use for pagination.

In blog.js:

import React from 'react'
import Link from 'next/link'
import Butter from 'buttercms'

const butter = Butter('')

export default class extends React.Component {
  static async getInitialProps({ query }) {
    let page = query.page || 1;

    const resp = await butter.post.list({page: page, page_size: 10})    
    return resp.data;
  }
  render() {
    const { next_page, previous_page } = this.props.meta;

    return (
      <div>
        {this.props.data.map((post) => {
          return (
            <div><a href={`/post/${post.slug}`}>{post.title}</a></div>
          )
        })}

        <div>
          {previous_page && <Link href={`/?page=${previous_page}`}><a>Prev</a></Link>}
          {next_page && <Link href={`/?page=${next_page}`}><a>Next</a></Link>}
        </div>
      </div>
    )
  }
}

With Next.js getInitialProps will execute on the server on initial page loads, and then on the client when navigating to a different routes using the built-in <Link> component. getInitialProps also receives a context object with various properties – we access the query property for handling pagination. We are fetching posts from a ButterCMS test account – sign in with Github to setup your own posts.

In our render() method we use some clever syntax to only display pagination links only when they're applicable. Our post links will take us to a 404 – we'll get these working next.

Setup the Blog Post page to list a single post

We'll also update our post component to fetch blog posts via slug and render the title and body. See a full list of available post properties in our API reference:

import React from 'react'
import Butter from 'buttercms'

const butter = Butter('')

export default class extends React.Component {
  static async getInitialProps({ query }) {
    const resp = await butter.post.retrieve(query.slug);  
    return resp.data;
  }
  render() {
    const post = this.props.data;

    return (
      <div>
        <h1>{post.title}</h1>
        <div dangerouslySetInnerHTML={{ __html: post.body }} />
      </div>
    )
  }
}

Add routes to the server

To get our post links working we need to setup dynamic routing for our blog posts. First, create a custom server ./server.js that routes all /posts/:slug URLs to our post component, and the /posts URL to our index page:

const next = require('next')
const express = require('express')
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
const port = 3000

app.prepare().then(() => {
  const server = express()

  server.get('/posts', (req, res) => {
    return app.render(req, res, '/index', { slug: req.params.slug })
  })

  server.get('/posts/:slug', (req, res) => {
    return app.render(req, res, '/post', { slug: req.params.slug })
  })

  server.get('*', (req, res) => {
    return handle(req, res)
  })

  server.listen(port, (err) => {
    if (err) throw err
    console.log(`> Ready on http://localhost:${port}`)
  })
})

Finally, update our package.json start script to use our customer server and restart:

"scripts": {
  "start": "node server.js"
}

SEO

Next.js provides a Head component for setting HTML titles and meta tags. Add import Head from 'next/head' to the top of ./pages/post.js and use the component in the render() method:

render() {
  const post = this.props.data;

  return (
    <div>
      <Head>
        <title>{post.seo_title}</title>
        <meta name="description" content={post.meta_description} />
        <meta name="og:image" content={post.featured_image} />
      </Head>

      <h1>{post.title}</h1>
      <div dangerouslySetInnerHTML={{__html: post.body}} />
    </div>
  )
}}

Restart the server and inspect the HTML source of a post to verify that tags are getting set correctly. Now our app has a working blog that can be updated easily in the ButterCMS dashboard.

That's it! The blog posts created in your Butter dashboard will immediately show up in your app.

Get Started for Free

Try Butter free for 14 days

See for yourself what makes Butter the best NextJS blog engine out there. Click the button below to sign up for your free 14-day trial.