Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

VenomIsAwesome's avatar

Use Laravel 6 and NodeJS in API Rest

I am looking for my first job, my specialty is JavaScript development, I wanted to take over PHP and laravel to acquire new skills.

I started a project that will help me in my everyday life.

I realize API Rest with laravel, it is almost finished.

The front part will be managed with ReactJS, the API is therefore the back part.

I am testing my API with postman.

One of my features of my project consists in recovering data from a website (title, text, etc.)

I added this functionality in my API, which I managed to do but only for static sites or the sites that I target are generated with JavaScript.

I have tried several solution with laravel:

Solution 1:

Use puphpeteer and SimpleHtmlDomParser.

Result: I have an exception error as the "node" command does not detect.

After several searches, I tried a lot of solution for 3 hours and I could not resolve this error.

Solution 2: Use PhantomJS with SimpleHtmlDomParser and CasperJS.

Result: I get an error related to CasperJS concerning the tempname () function, the creation of a temporary file failed.

I researched and failed to resolve the problem.

Solution 3: Use a NodeJS script and use cheerio.js / puppeter.

Result: I got the data I wanted, and that in 10 min.

After that I started to think about the choice of technologies used and I asked myself several questions.

Why used NodeJS and Laravel in the same project knowing that these are 2 server-side technologies.

Initially I planned to stay on Laravel because my API is almost finished.

In the end, I think I used NodeJS just for the functionality I need, but I'm afraid it will add to the project.

Finally, could this not make it more difficult to deploy the application to production because I will have to make NodeJS and Laravel coexist.

I ask myself a lot of questions, it can be easy to answer these questions but I would like to have your opinion.

Thank you in advance for your answers.

If you don't understand part of my post, don't hesitate to ask me questions.

0 likes
2 replies
bobbybouwmann's avatar

You probably use node in your tech stack anyway, because you need to compile your React code to JS. So it's not odd to have a script around to perform some action. Your first and section solution also requires node, but they trigger node from PHP ;)

In the end you should use what works for you. So if you like to write your API in Laravel, stick with that ;) It's true you can do it in Node as well, but that might take you longer because it's another thing you need to learn.

VenomIsAwesome's avatar

It is true that Puphpeteer is a derivative of the javascript version.

ReactJS will be just a SPA application, I would not use it in Laravel, React will just use the API that I developed under Laravel.

If I chose Laravel it was because I wanted to get my chances of finding a job since I am a junior developer, You should know that I plan to learn Node JS in the near future.

But on the other hand, JavaScript technologies have become popular, NodeJS is often recommended for REST APIs.

I wonder about the relevance of learning Laravel rather than NodeJS.

I also said to myself, the laravel API must be able to execute the NodeJS script, for scraping data after accessing a user's action.

How could we execute a NodeJS script from a Laravel controller?

Please or to participate in this conversation.