PHPackages                             nodejs-php-fallback/nodejs-php-fallback - 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. nodejs-php-fallback/nodejs-php-fallback

ActiveComposer-plugin[Utility &amp; Helpers](/categories/utility)

nodejs-php-fallback/nodejs-php-fallback
=======================================

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available

1.6.0(5y ago)17454.7k↓27.8%38MITPHPPHP &gt;=7.3

Since Jul 22Pushed 5y ago1 watchersCompare

[ Source](https://github.com/kylekatarnls/nodejs-php-fallback)[ Packagist](https://packagist.org/packages/nodejs-php-fallback/nodejs-php-fallback)[ GitHub Sponsors](https://github.com/kylekatarnls)[ Fund](https://opencollective.com/Carbon)[ RSS](/packages/nodejs-php-fallback-nodejs-php-fallback/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (27)Used By (8)

NodejsPhpFallback
=================

[](#nodejsphpfallback)

[![Latest Stable Version](https://camo.githubusercontent.com/b00b3007c72f4698452501ae2162d2610089e476a790fb33f8b37abde7cd2c50/68747470733a2f2f706f7365722e707567782e6f72672f6e6f64656a732d7068702d66616c6c6261636b2f6e6f64656a732d7068702d66616c6c6261636b2f762f737461626c652e706e67)](https://packagist.org/packages/nodejs-php-fallback/nodejs-php-fallback)[![Build Status](https://camo.githubusercontent.com/f164a6758130f4eaacfa233ab9a64c8d413d00108c9e232da9c4bfe7a2c07287/68747470733a2f2f7472617669732d63692e6f72672f6b796c656b617461726e6c732f6e6f64656a732d7068702d66616c6c6261636b2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/kylekatarnls/nodejs-php-fallback)[![StyleCI](https://camo.githubusercontent.com/fc6f1084f1dc810c885a134338ab8768afadf13fb2ac54d3ad5069b48f5eb38d/68747470733a2f2f7374796c6563692e696f2f7265706f732f36323935383634352f736869656c643f7374796c653d666c6174)](https://styleci.io/repos/62958645)[![Test Coverage](https://camo.githubusercontent.com/28fd492c3eb8858ce3df490a2e84fbbcfb894a931caff6128f4a5a2916382d6c/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6b796c656b617461726e6c732f6e6f64656a732d7068702d66616c6c6261636b2f6261646765732f636f7665726167652e737667)](https://codecov.io/github/kylekatarnls/nodejs-php-fallback?branch=master)[![Code Climate](https://camo.githubusercontent.com/4acdd3250ea1fede26caae88014b71479d1acc73cb6b8b5ca7e7d2ea360b8305/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6b796c656b617461726e6c732f6e6f64656a732d7068702d66616c6c6261636b2f6261646765732f6770612e737667)](https://codeclimate.com/github/kylekatarnls/nodejs-php-fallback)

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available.

Usage
-----

[](#usage)

Edit **composer.json** to add **nodejs-php-fallback** to *"require"*, your *"npm"* dependancies to *"extra"* and `"NodejsPhpFallback\\NodejsPhpFallback::install"`to both *"post-install-cmd"* and *"post-update-cmd"* in *"scripts"*

For example, to use node.js **stylus** and fallback to the php **kylekatarnls/stylus** port, use:

```
...
"require": {
    "nodejs-php-fallback/nodejs-php-fallback": "*",
    "kylekatarnls/stylus": "*"
},
"extra": {
    "npm": {
        "stylus": "^0.54"
    }
},
"scripts": {
    "post-install-cmd": [
        "NodejsPhpFallback\\NodejsPhpFallback::install"
    ],
    "post-update-cmd": [
        "NodejsPhpFallback\\NodejsPhpFallback::install"
    ]
},
...
```

With this configuration, both node **stylus** and php **kylekatarnls/stylus** packages will be installed and updated when you update or install with composer if node is installed, else, only the php package will be.

So you can easily create a function that will try first to call the node package, then else the php one:

```
use NodejsPhpFallback\NodejsPhpFallback;
use Stylus\Stylus;

function getCssFromStylusFile($stylusFile)
{
    $node = new NodejsPhpFallback();
    $fallback = function () use ($stylusFile) {
        $stylus = new Stylus();

        return $stylus->fromFile($stylusFile)->toString();
    };

    return $node->execModuleScript('stylus', 'bin/stylus', '--print ' . escapeshellarg($stylusFile), $fallback);
}

$css = getCssFromStylusFile('path/to/my-stylus-file.styl');
```

Here `$css` will contain CSS code rendered from your stylus file, no matter node is installed or not. So you can install node on your production environment to benefit of the last official version of a npm package but any one can test or develop your project with no need to install node.

Note: the PHP fallback can be a simple php function, not necessarily a call to a class or a composer package.

### Settings

[](#settings)

The *extra.npm* can be an object with npm required packages as key and versions for each of them as value (see  for version definition). You can also set it as an array of package names, it's the same as specify all packages dependancies with `"*"` version. Else if you need only one package and don't care about the version, just pass it as a string:

Array configuration:

```
"extra": {
    "npm": [
        "hamljs",
        "kraken-js"
    ]
},
```

String configuration:

```
"extra": {
    "npm": "express"
},
```

### Ask the user to confirm package install

[](#ask-the-user-to-confirm-package-install)

You can use the `npm-confirm` setting to ask the user if he want to install one or more npm package. This should be used to make the user aware npm packages will be installed, and what for they are. This is also a way to not install optional packages if they are used in a user specific case.

```
"extra": {
    "npm": [
        "stylus",
        "less",
        "clean-css",
    ],
    "npm-confirm": {
        "stylus": "This package is needed if you have stylus files.",
        "less": "This package is needed if you have less files."
    }
},
```

With the configuration above, when the user will execute `compoers update` or `composer install`, he will be asked the following:

```
The node package [stylus] can be installed:
This package is needed if you have stylus files.
Would you like to install/update it? (if you're not sure, you can safely press Y to get the package ready to use if you need it later) [Y/N]

The node package [less] can be installed:
This package is needed if you have less files.
Would you like to install/update it? (if you're not sure, you can safely press Y to get the package ready to use if you need it later) [Y/N]

```

Each of `stylus` and `less` packages will be installed only if the user enter `Y` on confirm or if he ran the command with the mode `--no-interaction`.

The `clean-css` package will be installed with no confirm.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity44

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 96.9% 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 ~62 days

Recently: every ~234 days

Total

26

Last Release

2026d ago

PHP version history (2 changes)1.0.2PHP &gt;=5.3.0

1.6.0PHP &gt;=7.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/df90c422f521bf26355c3e185a59fe7afb35531af56244dfaec03ee1d0ca6f24?d=identicon)[kylekatarn](/maintainers/kylekatarn)

---

Top Contributors

[![kylekatarnls](https://avatars.githubusercontent.com/u/5966783?v=4)](https://github.com/kylekatarnls "kylekatarnls (94 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (3 commits)")

---

Tags

adaptercomposernodejsnpmphpwrapper

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nodejs-php-fallback-nodejs-php-fallback/health.svg)

```
[![Health](https://phpackages.com/badges/nodejs-php-fallback-nodejs-php-fallback/health.svg)](https://phpackages.com/packages/nodejs-php-fallback-nodejs-php-fallback)
```

###  Alternatives

[vaimo/composer-patches

Applies a patch from a local or remote file to any package that is part of a given composer project. Patches can be defined both on project and on package level. Optional support for patch versioning, sequencing, custom patch applier configuration and patch command for testing/troubleshooting added patches.

2994.3M16](/packages/vaimo-composer-patches)[mglaman/composer-drupal-lenient

1317.4M15](/packages/mglaman-composer-drupal-lenient)[drupal/core-composer-scaffold

A flexible Composer project scaffold builder.

5341.9M446](/packages/drupal-core-composer-scaffold)[drupal/core-project-message

Adds a message after Composer installation.

2122.6M172](/packages/drupal-core-project-message)[olvlvl/composer-attribute-collector

A convenient and near zero-cost way to retrieve targets of PHP 8 attributes

184108.8k8](/packages/olvlvl-composer-attribute-collector)[lullabot/drainpipe

An automated build tool to allow projects to have a set standardized operations scripts.

41716.4k2](/packages/lullabot-drainpipe)

PHPackages © 2026

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