PHPackages                             lanre/jsrunner - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. lanre/jsrunner

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

lanre/jsrunner
==============

A simple PHP wrapper for running JavaScript code

v0.1.1(2y ago)27[9 PRs](https://github.com/oplanre/jsrunner/pulls)MITPHPPHP ^8.1

Since Feb 23Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/oplanre/jsrunner)[ Packagist](https://packagist.org/packages/lanre/jsrunner)[ RSS](/packages/lanre-jsrunner/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (12)Used By (0)

Server side rendering JavaScript in your PHP application
========================================================

[](#server-side-rendering-javascript-in-your-php-application)

[![Latest Version on Packagist](https://camo.githubusercontent.com/25cb47a249151a8948e3515aa617b7f453d35f640d9fdba3d82f29744bf1bbdb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c616e72652f6a7372756e6e65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lanre/jsrunner)[![Build Status](https://camo.githubusercontent.com/84f5002f5bc00fd8f0baaf857b2ef812dc09b3c1cd0bd31941a0d864e0f1c0a9/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6c616e72652f6a7372756e6e65722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/lanre/jsrunner)[![Total Downloads](https://camo.githubusercontent.com/835953255a3341f1d384419db6e9bd203d48ee1565ae55cca8499fd12e8f7eac/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c616e72652f6a7372756e6e65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lanre/jsrunner)

```
use Lame\JSRunner\Renderer;
use Lame\JSRunner\V8Engine as V8;

$engine = new V8();

$renderer = new Renderer($engine);

echo $renderer
    ->entry(__DIR__.'/../../public/js/app-server.js')
    ->render();

// My server rendered app!
```

- Works with any JavaScript framework that allows for server side rendering
- Runs with or without the V8Js PHP extension
- Requires minimal configuration This readme assumes you already have some know-how about building server rendered JavaScript apps.

Who's this package for?
-----------------------

[](#whos-this-package-for)

- Projects that want to call JavaScript from PHP seamlessly.
- Bilingual(PHP and JS/TS) projects that want to render their JS/TS on the server side.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require lanre/jsrunner
```

Usage
-----

[](#usage)

### Engines

[](#engines)

An engine executes a JS script on the server. This library ships with three engines: `V8Engine` which wraps some `V8Js` calls, so you'll need to install a PHP extension for this one, `BunEngine` and `NodeEngine` which build a bun/node script (respectively) at runtime and executes it in a new process. An engine can run a script, or an array of multiple scripts.

`V8Engine` is a lightweight wrapper around the `V8Js` class. You'll need to install the [v8js extension](https://github.com/phpv8/v8js) to use this engine.

`BunEngine` and `NodeEngine` write a temporary file with the necessary scripts to render your app, and executes it

in the appropriate environment. You'll need to have [node.js](https://nodejs.org) (for `NodeEngine`) or [bun](https//bun.sh) (for `BunEngine`) installed to use this engine.

### Rendering options

[](#rendering-options)

You can chain any amount of options before rendering the app to control how everything's going to be displayed.

```
echo $renderer
    ->enableIf($user->isAuthenticated())
    ->context('user', $user)
    ->entry(__DIR__.'/../../public/js/app-server.js')
    ->render();
```

#### `enable(): $this`

[](#enable-this)

Enables server side rendering. This is the default state.

#### `disable(): $this`

[](#disable-this)

Disables server side rendering. When disabled, the client script and the fallback html will be rendered instead.

#### `enableIf(bool $enabled = true): $this`

[](#enableifbool-enabled--true-this)

Conditionally enables server side rendering.

#### `debug(bool $debug = true): $this`

[](#debugbool-debug--true-this)

When debug is enabled, JavaScript errors will cause a php exception to throw. Without debug mode, the client script and the fallback html will be rendered instead so the app can be rendered from a clean slate.

#### `entry(string $entry): $this`

[](#entrystring-entry-this)

The path to your server script. The contents of this script will be run in the engine.

#### `context($context, $value = null): $this`

[](#contextcontext-value--null-this)

Context is passed to the server script in the `context` variable. This is useful for hydrating your application's state. Context can contain anything that json-serializable.

```
echo $renderer
    ->entry(__DIR__.'/../../public/js/app-server.js')
    ->context('user', ['name' => 'Sebastian'])
    ->render();
```

```
// app-server.js

store.user = context.user // { name: 'Sebastian' }

// Render the app...
```

Context can be passed as key &amp; value parameters, or as an array.

```
$renderer->context('user', ['name' => 'Sebastian']);
```

```
$renderer->context(['user' => ['name' => 'Sebastian']]);
```

#### `env($env, $value = null): $this`

[](#envenv-value--null-this)

Env variables are placed in `process.env` when the server script is executed. Env variables must be primitive values like numbers, strings or booleans.

```
$renderer->env('NODE_ENV', 'production');
```

```
$renderer->env(['NODE_ENV' => 'production']);
```

#### `fallback(string $fallback): $this`

[](#fallbackstring-fallback-this)

Sets the fallback html for when server side rendering fails or is disabled. You can use this to render a container for the client script to render the fresh app in.

```
$renderer->fallback('');
```

#### `resolveEntryWith(callable $resolver): $this`

[](#resolveentrywithcallable-resolver-this)

Add a callback to transform the entry when it gets resolved. It's useful to do this when creating the renderer so you don't have to deal with complex paths in your views.

```
echo $renderer
    ->resolveEntryWith(function (string $entry): string {
        return __DIR__."/../../public/js/{$entry}-server.js";
    })
    ->entry('app')
    ->render();
```

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/oplanre/jsrunner/blob/main/CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- Lanre Waju for creating this package
- [Sebastian De Deyne](https://github.com/sebastiandedeyne) for spatie/server-side-rendering which this package is based on
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance58

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 55.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

815d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/481db45e6eedb1cc562223508f3ca9d1b6766ede1afe0f154657ce12ee8d7b5a?d=identicon)[lanre](/maintainers/lanre)

---

Top Contributors

[![oplanre](https://avatars.githubusercontent.com/u/113967437?v=4)](https://github.com/oplanre "oplanre (5 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (4 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/lanre-jsrunner/health.svg)

```
[![Health](https://phpackages.com/badges/lanre-jsrunner/health.svg)](https://phpackages.com/packages/lanre-jsrunner)
```

###  Alternatives

[symplify/monorepo-builder

Not only Composer tools to build a Monorepo.

5205.3M82](/packages/symplify-monorepo-builder)[spatie/typescript-transformer

This is my package typescript-transformer

3706.5M16](/packages/spatie-typescript-transformer)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[shivas/versioning-bundle

Symfony application versioning, simple console command to manage version (with providers e.g. git tag) of your application using Semantic Versioning 2.0.0 recommendations

1121.2M1](/packages/shivas-versioning-bundle)[eclipxe/cfdiutils

PHP Common utilities for Mexican CFDI 3.2, 3.3 &amp; 4.0

141129.9k6](/packages/eclipxe-cfdiutils)[shyim/danger-php

Port of danger to PHP

8544.9k](/packages/shyim-danger-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
