Personal blog written from scratch using Node.js, Bootstrap, and MySQL. https://jrtechs.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
3.3 KiB

  1. ![PHP vs Node meme](media/fa157040d5849cc48de1cbec2c67ef69.jpg)
  2. It used to be the case that you wrote PHP for the backend and JavaScript on the
  3. front end. However, that has all changed with the invention of Node.js. Some kid
  4. invented a clever way to run JavaScript on the server. Now we can develop a
  5. website that runs JavaScript on both the front and back end. This is good right?
  6. We should all learn JavaScript. The one language to rule them all. Although
  7. Node.js has taken the web by storm, I would argue that there are cases where PHP
  8. is still relevant and even preferable.
  9. Where PHP Wins
  10. --------------
  11. The major benefit with PHP is the low development time. You can write a website
  12. in PHP much faster than you could with Node.js. PHP is simply easier to work
  13. with than Node.js. Things like GET, POST, and SESSION information is simply a
  14. variable that you reference. Doing the same things in node.js is trickier
  15. because they require node dependencies – which vary in quality. Next, PHP was
  16. built to work nicely with databases like Mongo, and MySQL. In PHP you can make
  17. database query without falling into the callback hell that you experience in
  18. Node.js. It is not impossible or impractical to work with databases in node.js,
  19. I have done it plenty of times. However, synchronization of the database calls
  20. can be tricky and requires more code than it does in PHP.
  21. Another key point is that PHP has been out for a longer amount of time so there
  22. is an abundance of code on the web for reference. Not only is there more code
  23. but there is also an abundance of tutorials, and books written on PHP. The last
  24. reason why I love PHP is that it is really easy to deploy. If you updated a file
  25. all you have to do is upload it to your apache web server. That’s it. With
  26. Node.js you would have to upload the file and restart the server for the change
  27. to take effect.
  28. Where Node.js Wins
  29. ------------------
  30. If you only want to know one language, Node.js wins because you can now just
  31. become a master at JavaScript. Many larger companies are starting to use Node.js
  32. simply because it is faster than PHP. The asynchronous calls in Node.js is a
  33. huge time saver for applications that heavily rely on database or API calls. The
  34. brilliant use of callback functions can make your application run wickedly fast.
  35. However, callback functions and synchronization promises can be a headache to
  36. write. Once you get into the groove of it, it is not terrible, but it will add
  37. development time to your project.
  38. Compared to PHP, Node.js is a newer language. There is currently a lot of people
  39. actively developing for it. Therefore, the libraries that you are using are
  40. newer and are often faster than their PHP counterparts. NPM is a lifesaver. NPM
  41. offers thousands of modules at your fingertips which can easily add
  42. functionality to your project.
  43. Conclusion
  44. ----------
  45. I don’t want to sound like I hate Node.js, I enjoy using both PHP and Node.js.
  46. PHP is better for smaller projects due to it’s fast development time. I would
  47. recommend Node.js for any project that deals with heavy database usage. The
  48. perfect use case for Node.js would be for a web API. If your project is heavily
  49. dependent on HTML - like a blog- I would urge you to use PHP.
  50. If you are still undecided, just learn Node.js. It pains me to say it but,
  51. Node.js is slowly taking over PHP.
  52. ![PHP developer meme](media/422d949d18969b9b2b8cf754ddc1e779.jpg)