Add Mosaicora to any Node.js application

Use the core npm package to build Mosaicora image URLs, publish crawler-readable social metadata, and optionally version refreshed image assets in any server-rendered or statically generated Node.js application.

What this integration does

  • Turns each page’s canonical URL into a stable Mosaicora image URL.
  • Provides the URL for the Open Graph and Twitter tags your rendering layer emits.
  • Supports deliberate and scheduled image URL versioning with v.
  • Builds and safely serializes optional JSON-LD render values.

Expected outcome

Your server or static build publishes one predictable Mosaicora image URL per page and can safely provide typed JSON-LD values when the image needs deliberate content.

How the pieces connect

The integration connects content your application already knows about to the metadata a social crawler can read.

  1. Application page data
  2. Canonical URL and optional render values
  3. Core npm helpers
  4. Server-rendered social metadata
  5. Social preview

Use this integration when

  • Your application renders HTML on the server or during a static build.
  • You can edit the document head or SEO metadata layer.
  • You need framework-level control instead of a Next.js-specific helper.

Choose another path

Choose the Next.js guide when App Router metadata can handle the integration for you.

Use the native Next.js package

Before you begin

  • A Node.js 20 or newer application that can publish server-rendered or statically generated HTML.
  • The public canonical URL for each integrated page.
  • Your public Mosaicora site ID.
  • Access to the template, document head, or SEO layer that emits meta and JSON-LD script tags.
Package
@mosaicora/plugin-mosaicora-core 1.0.4
Runtime
Node.js 20+
Language
TypeScript or JavaScript
License
MIT
1

Install the core package

Add the framework-agnostic ESM package to your application.

Install from the project root. The package is side-effect free and includes TypeScript declarations.

Install with pnpm

pnpm add @mosaicora/plugin-mosaicora-core

Expected result

  • The dependency appears in package.json.
  • The runtime can import ESM package exports.
2

Build the image URL

Turn the page’s canonical identity into a deterministic Mosaicora CDN address.

Call buildOgImageUrl on the server or during static generation. Pass the site ID and pageHref: the same absolute canonical URL your page publishes.

Use one pageHref for each public page identity. Publish an alternate route’s canonical URL before creating its Mosaicora image URL.

Generate the CDN URL

import { buildOgImageUrl } from "@mosaicora/plugin-mosaicora-core";

const imageUrl = buildOgImageUrl({
  siteId: "321cac22d2103fb1660c50bd",
  pageHref: "https://example.com/products/view",
});

Expected result

  • imageUrl starts with https://cdn.mosaicora.io/s/.
  • The URL ends in .jpg before any query string.
3

Version a refreshed social image

Add an opt-in v URL when an updated image should be fetched as a separate asset.

Set cacheVersion to a non-empty deployment, release, or content revision you control. It safely encodes the value, replaces a source URL’s existing v, and takes precedence over a cacheBuster schedule.

For automatic rotation, use cacheBuster: "monthly" as the least-frequent suitable schedule. When neither option is supplied, buildOgImageUrl preserves the existing URL behavior.

Manual image version

const imageUrl = buildOgImageUrl({
  siteId: "321cac22d2103fb1660c50bd",
  pageHref: "https://example.com/products/view",
  cacheVersion: "release-2026-07",
});

// https://cdn.mosaicora.io/s/321cac22d2103fb1660c50bd/products/view.jpg?v=release-2026-07

Monthly image version

const imageUrl = buildOgImageUrl({
  siteId: "321cac22d2103fb1660c50bd",
  pageHref: "https://example.com/products/view",
  cacheBuster: "monthly",
});

// For July 2026: https://cdn.mosaicora.io/s/321cac22d2103fb1660c50bd/products/view.jpg?v=2026-07
4

Publish the social metadata

Use the generated URL in standard Open Graph and X/Twitter tags.

Pass imageUrl into your framework, CMS, or template engine. Render these tags in the document head before returning the page to crawlers.

Framework-neutral HTML

<meta property="og:image" content="IMAGE_URL" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:image" content="IMAGE_URL" />
5

Supply the image-render content

Build and safely serialize JSON-LD values for the Mosaicora generator.

Keep your existing Schema.org fields and add mosaicora:og semantic values for content the generator should render exactly. These overrides guide the Open Graph image. They do not replace normal page metadata.

serializeJsonLd removes undefined values and escapes less-than characters so the result can be embedded in an HTML JSON-LD script element.

Build and serialize the override

import {
  buildMosaicoraOgJsonLd,
  serializeJsonLd,
} from "@mosaicora/plugin-mosaicora-core";

const jsonLd = buildMosaicoraOgJsonLd({
  schemaType: "Product",
  name: "Example product",
  offers: {
    "@type": "Offer",
    price: "49",
    priceCurrency: "USD",
  },
  mosaicoraOg: {
    schemaVersion: 3,
    semanticValues: {
      "content.title": "Example product",
      "content.description": "A polished product preview.",
      "product.price": "$49",
      "product.features": ["Fast setup", "Consistent previews"],
    },
  },
});

const serialized = serializeJsonLd(jsonLd);

Embed with your template engine

Insert serialized as the text content of an application/ld+json script.

<script type="application/ld+json">
  SERIALIZED_JSON_LD
</script>
6

Verify the published output

Check the server-rendered HTML, image URL, and JSON-LD together.

Publish the page at its canonical public URL, inspect the initial HTML response, and run the URL through the Open Graph Checker.

Confirm that the image metadata uses imageUrl and that the JSON-LD contains the same page identity and intended semantic render values.

If image content changed, verify that imageUrl ends with only the intended v value before requesting any optional platform refresh.

Expected result

  • The initial HTML contains og:image and twitter:image.
  • The JSON-LD script parses without errors.
  • The checker recognizes the Mosaicora CDN image.

Reference

Advanced usage

Deterministic URL rules

The same canonical input always maps to the same normalized image location.

  • The root path becomes https://cdn.mosaicora.io/s/{siteId}.jpg.
  • Nested paths remain below /s/{siteId}.
  • Retained page query entries are sorted by key and value, then percent-encoded into the CDN path before .jpg.
  • The reserved v cache token remains after .jpg; other post-.jpg query values are ignored for page lookup.
  • Hash fragments are ignored and UTF-8 paths remain readable.
  • cacheVersion replaces an existing v and wins over cacheBuster.
  • cacheBuster supports daily, weekly, monthly, and custom duration schedules.

Typed public contract

The package exports URL helpers, JSON-LD builders, and the complete v3 semantic contract.

  • MosaicoraOgOverride and MosaicoraOgSemanticValues
  • MosaicoraOgSemanticRole and role-specific value types
  • buildOgImageUrl, buildOgImageCacheBuster, and OgImageCacheBuster
  • OgImageUrlOptions, including cacheVersion and cacheBuster
  • serializeJsonLd for safe HTML embedding

Help

Troubleshooting

The package cannot be imported

Confirm the application uses Node.js 20+ and supports ESM imports. Import from the package root rather than a private dist path.

The social crawler does not see the tags

Move metadata generation to the server or static build. Tags injected only after browser hydration are not reliable for social crawlers.

The JSON-LD script is quoted or malformed

Embed the output from serializeJsonLd once as script text. Do not run JSON.stringify on the serialized string a second time.

A platform keeps showing an older social preview

Verify the public page now exposes the intended metadata and image, then set cacheVersion for the new asset or choose the least-frequent suitable cacheBuster schedule. A versioned image does not make a third-party platform re-crawl an already cached page preview.

Need help with another publishing workflow?

Open the dashboard to start with the current integrations, or contact us if you need a different workflow.