2
Mb3leb
5y

As per knowledge everyone here knows that nodejs express is single thread compared to laravel which is multithreaded.

So definitely laravel is better than NodeJS

Then why would someone choose nodejs over laravel?

Comments
  • 0
    ๐Ÿงท
  • 1
    @Coffe2Code what's your answer
  • 1
    @Mba3gar I'm just looking for answer like you mate. did that to receive notifs about comments
  • 0
    No hesitation before jumping to that conclusion, haha ๐Ÿ˜Œ I don't know though (something something non-blocking IO and simplicity?). There's always pros and cons.
  • 3
    Because node is the new kid on the block and everyone wants to be like him
  • 0
    Very weird, i just need a clear answer why would someone build his Rest api on nodejs express taking into consideration it's single thread
  • 0
    ๐Ÿ“Œ๐Ÿ”Ž
  • 0
    but I think it's all about asynchronous operations. If you make a synchronous call which is CPU intensive it will block the thread. Therefore you use an asynchronous function. This function will be triggered and the thread goes right to the next request while the CPU intensive function is executed without blocking.

    ----

    random comment from the internet
  • 0
    @Coffe2Code not convinced
  • 0
    For those who pinned this rant for news check the following link but still not convinced too

    https://geeksforgeeks.org/php-vs-no...
  • 0
    @Mba3gar i wasn't looking for first result on Google nodejs vs php, rather a concrete firsthand example from devrant member ๐Ÿ˜‰
  • 0
    @myss same to be honest
  • 1
    There could be several reasons for that decision:
    1. ecosystem
    2. performance doesn't matter everytime
    3. you can write better js than PHP - so you are building your app way fast er
    4. node doesn't scale so Bad through the nio
    5. node can also make use of multiple cores - making it somewhat multithreaded
  • 0
    @Minion how you can make nodejs multithreaded ?
  • 3
    Personally I love javascript, so developing with a MEAN stack makes development quick for me.

    But let's say that I really need to have a fast api, maybe I'd go with Laravel, but then I'd have to learn PHP. Why not learn C# and go with dotnet core? That's even faster than Laravel.

    Personally I think it's one of those for most people. Either the love for JS, or not wanting to learn to PHP.
  • 1
    @Mba3gar there is the cluster module and now worker threads
  • 1
    In JS only the event loop is single threaded.

    That means, don't write blocking code, or cpu intensive code in the main thread.

    The node execution model is a bit different than the rest of the languages.

    Javascript is a language designed to be the ugly kid of lisp (expressive and powerful) and C (familiar).

    So, it's powerful, yet familiar.

    Javascript supports continuation passing style (aka callbacks) and higher order functions.

    Which are just killer features that allows one to write more powerful and readable abstractions.

    Yes, it has its drawbacks, but if you are diligent in learning the language you get to be a better programmer.

    It's way more than just hype, as someone said. That's just the 10 second answer to appear smarter than the rest.

    If you are really interested in knowing the power of node, I'd recommend you start by reading about the event loop. You'll realize that JS is a very powerfull concurrent language, which php isn't.
  • 0
    @galileopy perfect answer, @Coffee2Code check this
  • 0
    Swoole it's the next evolution for PHP/Laravel, just look how you can write async code on it.
    https://www.swoole.co.uk/

    P.S and it performs better than node on concurrency as much as 2X
  • 0
    @mowgli share with us more your knowledge about it am really interested to know more.
  • 1
    @Mba3gar Sure thing, i'm working with swoole right now and it performs amazing, we have to create a TCP client and a TCP proxy on the same project and I could make it super easy with swoole, sure, you need to change a little bit how you write code in PHP, but it's awesome how it handles the concurrent users, i have made a stress test with like 5000 threads and it just take 1.3% of ram and 5% of CPU, if you have made it with php-fpm it will take as much as 16GB of ram and all the cores working at 100%, you can add it to laravel/lumen too -> https://github.com/swooletw/...
  • 1
    this is a http benchmark, you can't use https on swoole, but you can, however have a proxy behind it (I prefer haproxy ) to act as the SSL terminator, some benchmarking -> https://github.com/swoole/...
  • 1
    i started using node this week because it was a new project, i didn't know what to use and i had npm installed. performance isn't important to me since it's a small task, and while i'm familiar with both js and php, i only heard about laravel now
Add Comment