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

wordpress-playground-handler

v1.1.3

Published

A Node.js library for creating and managing WordPress Playground instances with PHP request handling capabilities. Optimized for Node.js runtime environments.

Readme

WordPress Playground Handler

A Node.js library for building serverless Headless WordPress applications without PHP server dependencies. By leveraging WordPress Playground's PHP runtime directly in Node.js, this package enables you to create Headless WordPress apps that can be deployed to platforms like Vercel - no PHP server or WordPress installation required. Simply make direct requests to WordPress's APIs and runtime from your Node.js code.

Features

  • 🚀 Singleton Pattern: Efficiently manages Playground instances with automatic caching
  • 🔧 Blueprint Support: Configure WordPress setup, plugins, and constants via blueprints
  • 📁 Directory Mounting: Mount local directories (database, plugins, themes, etc.)
  • 🌐 Direct API Access: Make requests directly to WordPress REST API and PHP runtime
  • 📦 TypeScript Ready: Full TypeScript support with comprehensive type definitions
  • Dynamic WordPress: Automatically fetches latest WordPress releases and plugins
  • 🧪 Testing Friendly: Perfect for headless testing and automation

Installation

npm install wordpress-playground-handler

Quick Start

import { getPlaygroundHandler, PHPRequest } from 'wordpress-playground-handler';

// Initialize WordPress Playground (singleton - only initializes once)
const handler = await getPlaygroundHandler();

// Make requests to WordPress
const response = await handler.request({
  method: 'GET',
  url: '/wp-json/wp/v2/posts'
} as PHPRequest);

console.log(JSON.parse(response.text));

API Reference

getPlaygroundHandler(options?: PlaygroundOptions)

Returns a Promise that resolves to a PHPRequestHandler. Uses singleton pattern for efficient resource management.

Options

interface PlaygroundOptions {
  blueprintPath?: string;    // Path to blueprint.json file
  blueprint?: Blueprint;     // Blueprint object (takes precedence over blueprintPath)
  mountPaths?: MountPaths;   // Local directories to mount
}

interface MountPaths {
  databasePath?: string;     // Mount database directory
  muPluginsPath?: string;    // Mount mu-plugins directory
}

If no options are provided, defaults to ./wordpress/blueprint.json.

Exported Types

  • PHPRequestHandler - Main handler for making requests
  • PHPRequest - Request interface
  • PHPResponse - Response interface
  • Blueprint - Blueprint configuration interface

Usage Examples

Basic Setup with Blueprint

import { getPlaygroundHandler, Blueprint } from 'wordpress-playground-handler';

const blueprint: Blueprint = {
  steps: [
    { step: "runWpInstallationWizard", options: {} },
    {
      step: "installPlugin",
      pluginData: {
        resource: "wordpress.org/plugins",
        slug: "akismet"
      }
    },
    {
      step: "defineWpConfigConsts",
      consts: {
        "JWT_AUTH_SECRET_KEY": "your-secret-key",
        "JWT_AUTH_CORS_ENABLE": true
      }
    }
  ]
};

const handler = await getPlaygroundHandler({ blueprint });

Mounting Local Directories

import { getPlaygroundHandler } from 'wordpress-playground-handler';
import { resolve } from 'path';

const handler = await getPlaygroundHandler({
  blueprintPath: './wordpress/blueprint.json',
  mountPaths: {
    databasePath: resolve('./database'),
    muPluginsPath: resolve('./mu-plugins')
  }
});

JWT Authentication Flow

import { getPlaygroundHandler, PHPRequest } from 'wordpress-playground-handler';

const handler = await getPlaygroundHandler();

// Get JWT token
const tokenResponse = await handler.request({
  method: "POST",
  url: "/wp-json/jwt-auth/v1/token",
  headers: { "Content-Type": "application/json" },
  body: {
    username: "admin",
    password: "password"
  }
} as PHPRequest);

const { token } = JSON.parse(tokenResponse.text);

// Use token for authenticated requests
const userResponse = await handler.request({
  method: "GET",
  url: "/wp-json/wp/v2/users/me",
  headers: { "Authorization": `Bearer ${token}` }
} as PHPRequest);

console.log('User info:', JSON.parse(userResponse.text));

Custom REST API Endpoints

// Create a post
const createPost = await handler.request({
  method: "POST",
  url: "/wp-json/wp/v2/posts",
  headers: {
    "Content-Type": "application/json",
    "Authorization": `Bearer ${token}`
  },
  body: {
    title: "My New Post",
    content: "This is the post content",
    status: "publish"
  }
} as PHPRequest);

// Get all posts
const getPosts = await handler.request({
  method: "GET",
  url: "/wp-json/wp/v2/posts"
} as PHPRequest);

Development

To work on this package locally:

git clone <repository-url>
cd wordpress-playground-handler
npm install
npm run build
npm test

Running the Example

npm run example

This runs the example in the example/ directory which demonstrates typical usage patterns.

Requirements

  • Node.js v18+
  • NPM or Yarn

License

MIT

References