How can I use PHP libraries from composer when I start using Node.js?

So we have some legacy PHP libraries in our organization which are used in almost all the applications. I wish to start a new project but will I be able to use those PHP libraries without converting them into JavaScript?

Shreyansh Pandey's photo

Hey, sounds like a pretty interesting question. Now, there are two options for you: one might sound intuitive and the other might sound a little obvious.

So, the first option you have is to turn them into microservices. If it's your own customer composer library, you can deploy it as a microservice and use it with whatever application you want. The con of this approach is the fact that you can break dependant applications if the microservices backend fails.

The second one is that almost everything for PHP is available for Node.js with minor or no changes. You can try going that way and if that doesn't work out, you might have to re-write them. This really gives a nice performance boost as you'll write some code in the language which the engine can run.

Another, but not-so-favoured method will be to to use php-fpm. Go to this link to see how.

If you need help in conversion or with anything else, feel free to drop me a line! :)

Atul Sharma's photo

As clearly pointed out by Shreyansh Pandey , either host the php libraries somewhere and communicate with them whenever required using JSON (Micro-Services Architecture) or find alternatives to the libraries.