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 🙏

© 2026 – Pkg Stats / Ryan Hefner

jsharmony-cms-sdk-express

v1.0.4

Published

jsHarmony CMS SDK for Node.js / Express

Downloads

3

Readme

jsharmony-cms-sdk-express

jsHarmony CMS SDK for Node.js / Express

Installation

Installation and integration instructions are available at jsHarmonyCMS.com


API Documentation


jsHarmonyCmsRouter

jsHarmonyCmsEditor Class (Client JS)


jsHarmonyCmsRouter Class


jsHarmonyCmsRouter Constructor

new jsHarmonyCmsRouter(config)

Arguments

  • config (Object) :: Object with one or more of the configuration keys below:
{
  content_path: null,
  //(string) File path to published CMS content files

  redirect_listing_path: null,
  //(string) Path to redirect listing JSON file (relative to content_path)

  default_document: 'index.html',
  //(string) Default Directory Document

  strict_url_resolution: false,
  //(bool) Whether to support URL variations (appending "/" or Default Document)

  passthru_timeout: 30,
  //(int) Maximum number of seconds for passthru request

  cms_clientjs_editor_launcher_path: '/.jsHarmonyCms/jsHarmonyCmsEditor.js',
  //(string) Path where router will serve the client-side JS script that launches CMS Editor

  cms_server_urls: [],
  //Array(string) The CMS Server URLs that will be enabled for Page Editing (set to '*' to enable any remote CMS)
  //  * Used by page.editorScript, and the getEditorScript function
  //  * NOT used by jsHarmonyCmsEditor.js - the launcher instead uses access_keys for validating the remote CMS
}

Example

var cmsRouter = new jsHarmonyCmsRouter({ cms_server_urls: ['https://cms.example.com'] });

Public Properties


onError

function(err, req, res, next){ }

Function executed when an unexpected error occurs

cmsRouter.onError = function(err, req, res, next){ console.error(err); };

onPageRender

function(pageFile, req, res, next){ }

Function executed to render the page

cmsRouter.onPageRender = function(pageFile, req, res, next){ res.end(pageFile); }

onRedirect

function(redirect, req, res, next){ }

Function executed when a matching redirect has been found

cmsRouter.onRedirect = function(redirect, req, res, next){ /* return false to not follow redirect */ }

Public Methods


getRouter

<jsHarmonyCmsRouter>.getRouter(options)

Main Entry Point - CMS Express.js Router Application

Parameters

  • options: (object) (Optional) Options
    {
       serveContent: (bool),
       //(Optional, default true) Whether the router should serve static content from config.content_path
    
       serveRedirects: (bool),
       //(Optional, default true) Whether the router should serve redirects
    
       servePages: (bool)
       //(Optional, default true) Whether the router should serve pages, based on the request URL
    
       serveCmsEditorScript: (bool)
       //(Optional, default true) Whether the router should serve the CMS Editor Launcher script at config.cms_clientjs_editor_launcher_path
    
       generate404OnNotFound: (bool)
       //(Optional, default false) Whether the router should generate a 404 page if no matching page was found
    }

Returns

(function) Express.js Route

Example

app.use(cmsRouter.getRouter({ generate404OnNotFound: true }));

getStandalone

<jsHarmonyCmsRouter>.getStandalone(req, url)

Main Entry Point - Load Standalone CMS Content

Parameters:

  • req: (object) Express.js Request

  • url: (string) (Optional) CMS Page URL

    Use Full URL, Root-relative URL, or leave blank to use current URL from Express.js Request

Returns

(object) Page Object, with additional properties: isInEditor, editorContent, notFound

If page is opened from CMS Editor or Not Found, an empty Page Object will be returned

Page Object {
  seo: {
      title: (string),   //Title for HEAD tag
      keywords: (string),
      metadesc: (string),
      canonical_url: (string)
  },
  css: (string),
  js: (string),
  header: (string),
  footer: (string),
  title: (string),      //Title for Page Body Content
  content: {
      <content_area_name>: <content> (string)
  },
  properties: {
      <property_name>: <property_value>
  },
  page_template_id: (string),
  isInEditor: (bool),     //Whether the page was opened from the CMS Editor
  editorScript: (string), //If page was opened from a CMS Editor in config.cms_server_urls, the HTML script to launch the Editor
  notFound: (bool)        //Whether the page was Not Found (page data will return empty)
}

Example

app.get('/standalone_page', async function(req, res, next){
  var page = await cmsClient.getStandalone(req);
  res.render('standalone_page.ejs', { page: page });
});

isInEditor

<jsHarmonyCmsRouter>.isInEditor()

Checks whether the page is in CMS Edit mode

Parameters

N/A

Returns

(bool) True if this page was opened from the CMS Editor

Example

if(cmsRouter.isInEditor()){ console.log('Editor'); }

resolve

<jsHarmonyCmsRouter>.resolve(url, options)

Converts URL to CMS Content Path

Parameters

  • url: (string) CMS Page URL

    Use Full URL or Root-relative URL

  • options: (object) (Optional) Options

    {
       // Whether to try URL variations (adding "/", "/<default_document>")
       strictUrlResolution: (bool), 
    
       // Starting Variation ID
       variation: (int)
    }

Returns

(string) CMS Content Path

Example

var contentPath = cmsRouter.resolve(targetUrl);

route

<jsHarmonyCmsRouter>.route(url)

Run CMS router on the target URL

Parameters

  • url: (string) CMS Page URL

    Use Full URL or Root-relative URL

Returns

(object) Page, Redirect, or null if Not Found

Page {
    type: 'page',
    content: (string) 'Page file content'
}

Redirect {
    type: 'redirect',
    redirect: {
        http_code: (string) '301', '302', or 'PASSTHRU',
        url: (string) 'destination/url'
    }
}

Example

var routeDest = cmsRouter.route(targetUrl);

getPageData

<jsHarmonyCmsRouter>.getPageData(url, options)

Get CMS Page Data

Parameters

  • url: (string) CMS Page URL

    Use Full URL or Root-relative URL

  • options: (object) (Optional) Options

    {
       // Starting Variation ID
       variation: (int)
    }

Returns

(object) Page Object, or null if not found

Page Object {
  seo: {
      title: (string),   //Title for HEAD tag
      keywords: (string),
      metadesc: (string),
      canonical_url: (string)
  },
  css: (string),
  js: (string),
  header: (string),
  footer: (string),
  title: (string),      //Title for Page Body Content
  content: {
      <content_area_name>: <content> (string)
  },
  properties: {
      <property_name>: <property_value>
  },
  page_template_id: (string)
}

Example

var pageData = cmsRouter.getPageData(targetUrl);

getPageFile

<jsHarmonyCmsRouter>.getPageFile(url, options)

Get CMS Page File

Parameters

  • url: (string) CMS Page URL

    Use Full URL or Root-relative URL

  • options: (object) (Optional) Options

    {
       // Starting Variation ID
       variation: (int)
    }

Returns

(buffer) Page Content

Error is thrown if page is not found

Example

var pageFile = cmsRouter.getPageFile(targetUrl);

getRedirectData

<jsHarmonyCmsRouter>.getRedirectData()

Get CMS Redirect Data

Requires config.redirect_listing_path to be defined

Returns

Array(Redirect Object) Redirects

Redirect Object {
    http_code: (string) '301', '302', or 'PASSTHRU',
    url: (string) 'destination/url',
}

Example

var cmsRedirects = cmsRouter.getRedirectData();

getEditorScript

<jsHarmonyCmsRouter>.getEditorScript(req)

Generate script for CMS Editor

Parameters

  • req: (object) Express.js Request

Returns

(string) HTML Code to launch the CMS Editor

If the page was not launched from the CMS Editor, an empty string will be returned

Security

The querystring jshcms_url parameter is validated against config.cms_server_urls

If the CMS Server is not found in config.cms_server_urls, an empty string will be returned

Example

res.send(cmsRouter.getEditorScript(req));

matchRedirect

<jsHarmonyCmsRouter>.matchRedirect(redirects, url)

Check if URL matches redirects and return first match

Parameters

  • redirects: Array(object) Array of CMS Redirects (from getRedirectData function)

  • url: (string) Target URL to match against the CMS Redirects

    Use Full URL or Root-relative URL

Returns

(object) Redirect

Redirect Object {
  http_code: (string) '301', '302', or 'PASSTHRU',
  url: (string) '<destination url>'
}

Example

var redirect = cmsRouter.matchRedirect(cmsRedirects);
if(redirect && (redirect.http_code=='301')){
  res.writeHead(301,{ 'Location': redirect.url });
  res.end();
}

generate404

<jsHarmonyCmsRouter>.generate404(req, res)

Generate a 404 Not Found page in Express.js

Parameters

  • req: (object) Express.js Request
  • res: (object) Express.js Response

Example

cmsRouter.generate404(req, res);

generateError

<jsHarmonyCmsRouter>.generateError(req, res, err)

Generate a 500 Error page in Express.js

Parameters

  • req: (object) Express.js Request
  • res: (object) Express.js Response
  • err: (object|string) Error object or string text

Example

cmsRouter.generateError(req, res, 'An unexpected error has occurred.');

jsHarmonyCmsEditor Class (Client JS)


jsHarmonyCmsEditor Constructor

jsHarmonyCmsEditor(config)

Arguments

  • config (Object) :: Object with one or more of the configuration keys below:
{
  access_keys: [],
  //Array(string) CMS Editor Access Keys, used to validate remote CMS URL
}

Example

//Load the CMS Editor in this page
jsHarmonyCmsEditor({ access_keys: ['*****ACCESS_KEY*****'] });