Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,154,748 members, 7,824,154 topics. Date: Saturday, 11 May 2024 at 12:56 AM

10 Weeks Of Node.js After 10 Years Of PHP - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / 10 Weeks Of Node.js After 10 Years Of PHP (2120 Views)

PHP/ Node JS Web Developer Is Urgently Needed / Is Node.js A Future??? / Node.js Vs Php (2) (3) (4)

(1) (Reply) (Go Down)

10 Weeks Of Node.js After 10 Years Of PHP by Nobody: 6:51am On Sep 08, 2016
A couple of months ago I started a new startup project at eFounders startup studio. I had been developing web applications using PHP for 10 years. I felt it was finally time to change my habits and to choose a more modern approach for developing them. I ditched PHP and started playing with the cool kids (no offense, PHP). This article tells you about my personal takeaways of this experience.

TL;DR; The switch was actually not that difficult for me as I was used to the paradigm of having a rich client and the server providing a slim JSON interface. The biggest gain for me is productivity. Having the same language on the server and the client side in makes things just much easier. On top of that, add the vast amount of NPM packages at your fingertips: things become really interesting.
Javascript syntax is not what makes Node.js better than PHP

In my opinion, your first steps with node.js will depend heavily on what you did before. Indeed, there are different ways to develop a web application in PHP. There is the old and ugly way everybody likes to hate and there is the better and modern way of developing in PHP. Depending on what you are doing right now, switching to a MEAN stack will either be a whole new world or not that crazy at all.

I tried both approaches. When developing in PHP the “modern” way, there were lots of javascript in the client and a server which acts more like a pure data API.

How I did things before on the server with PHP and the Laravel framework:

Route::get(‘user/{id}’, function($id) {
$user = User::find($id);
return Response::json($user->toArray());
});

And how I do the same thing now with node.js, Express and mongoose

app.route(‘/user/:id’).get(function(req, res) {
User.findById(req.params.id).exec(function(err, user) {
res.jsonp(user);
});
});

Looking at this you might wonder what all the fuzz is about and why people get so emotional when talking about different programming languages.
Async is your new best friend

The simple example above illustrates already one of the biggest differences though. All Input/Output functions in Javascript (reading a file, calling a database, API calls, …) are asynchronous procedures, whereas PHP gets executed sequentially. While you can just assign the output of a database call to a variable when working with PHP, you need work with callbacks or promises when doing this in Javascript.

This pattern is well known to every developer who touched a piece of javascript in his career (e.g. with jQuery). It’s however still something to get used to when doing multiple database calls, merging data and applying complex business logic.

The main challenge for me was to organize my code in a way that it stays readable (e.g. prevent the so-called Callback Hell). Once you figure this out and you know how to leverage the power of libraries like Async, everything becomes pretty easy. In fact, having the possibility to do several operations in parallel can be fun.
node.js’ package manager NPM proves the power of the Community

Chances are high that you were already using a package manager for one of your projects, e.g. composer in PHP or RubyGems for Ruby on Rails. The node.js package manager is called NPM.

At first sight, I thought there was nothing special about it, it just works as expected.However, when you look at the sheer amount of packages you can install (128k at the time of writing) the power of the community around node.js becomes clear. While using composer in PHP feels just like a convenient way to install libraries, NPM seems to be the center of the node.js community.

There is still more PHP source code available on the Internet than Javascript server side code. Most of it feels, however, outdated and doesn’t fit in the modern web development workflow. It seems there is node.js code available for every aspect of modern web development and you can solve most problems by installing the appropriate NPM package. This is a huge time-saver and changes the way you think about complex web applications.
#1 advantage: you only need to deal with one language

The biggest gain for me is however rooted in a very simple fact: Having the same language on the server and the client side. No more switching back and forth between languages context saves me a lot of time and is very pleasant.

While there is still a clear separation of concerns between the client and the server, all code looks the same and behaves the same way. When adding MongoDB as a data storage to the stack, JSON becomes omnipresent and there is just one way of accessing data objects. In addition, a lot of libraries work seamlessly on the server and the client at the same time (e.g. Moment.js) so chances are high that you just need to learn things once.
No regrets, definitely worth it!

Looking back, switching to Javascript on the server was less painful than expected. There is still a ton to explore for me and I’m pretty sure there are moments of desperation ahead. I would definitely recommend looking into the topic to someone who is about to start a new project and who is motivated to learn something new.

Web applications are nowadays heavily - if not solely - based on Javascript (AngularJS, Sails.js, Backbone… you name it) on the client side anyway. In this kind of setup, the server acts mostly as a thin data layer offering simple CRUD functions via an API. So why not just implement the API in Javascript as well and eliminate one language from the stack?

The simple fact of having the same language on the server had a big impact on my daily work and just for that I would do the switch again.

Ps: I’m looking for talented developers to join my team (in Paris) — ping me on Twitter if you wanna know more.

Source: Medium
Re: 10 Weeks Of Node.js After 10 Years Of PHP by jboy01(m): 10:37am On Sep 08, 2016
many developers would like to go node way but it still has few hosting company supporting it

3 Likes

Re: 10 Weeks Of Node.js After 10 Years Of PHP by Coyotejack(m): 12:48pm On Sep 08, 2016
nice write up op.
Re: 10 Weeks Of Node.js After 10 Years Of PHP by VenantCode(m): 2:38pm On Sep 08, 2016
jboy01:
many developers would like to go node way but it still has few hosting company supporting it
gone are the days where you look for hosting company, the present future is cloud hosting using Paas platform like Heroku and Iaas platform like Amazon AWS, Google App Engine.
Re: 10 Weeks Of Node.js After 10 Years Of PHP by jidez007: 2:40pm On Sep 08, 2016
VenantCode:
gone are the days where you look for hosting company, the present future is cloud hosting using Paas platform like Heroku and Iaas platform like Amazon AWS, Google App Engine.
Exactly. That kind of comment in this century sounds somehow.

2 Likes

Re: 10 Weeks Of Node.js After 10 Years Of PHP by Nobody: 3:59pm On Sep 08, 2016
jboy01:
many developers would like to go node way but it still has few hosting company supporting it

True, so many hosting companies don't support this... I just love the speed the language offers plus you can work with one language both on client and server side.
Re: 10 Weeks Of Node.js After 10 Years Of PHP by KvnqPrezo(m): 5:19pm On Sep 08, 2016
SORRY FOR DETRAILING
.
But I really need help!
.
I wanna start my website from scratch and I don't even know whether I should start creating pages or writing code...
.
And what folder is needed.
E.g
Index.php
Style.css
Login.php

Just help!!
Re: 10 Weeks Of Node.js After 10 Years Of PHP by VenantCode(m): 5:46pm On Sep 08, 2016
KvnqPrezo:
SORRY FOR DETRAILING
.
But I really need help!
.
I wanna start my website from scratch and I don't even know whether I should start creating pages or writing code...
.
And what folder is needed.
E.g
Index.php
Style.css
Login.php

Just help!!
It seems you settled for php for your project. If so first learn php online from sites like w3cschools.com, codecademy.com and then study to use a framework like Laravel. I still deeply believe that MEAN Stack would be nice to use.
Re: 10 Weeks Of Node.js After 10 Years Of PHP by KvnqPrezo(m): 7:14pm On Sep 08, 2016
VenantCode:
It seems you settled for php for your project. If so first learn php online from sites like w3cschools.com, codecademy.com and then study to use a framework like Laravel. I still deeply believe that MEAN Stack would be nice to use.
Am learning PHP with w3schools and with some Apps and Ebook.
,
I don't wanna wait till am an expert..
I wanna be working on my project and learning also..,
.
I'm still battling to know what a framework is and how it works... I even researched on bootstrap today but don't know what to use it for...
.
Yes I decided to use PHP because I heard that python hosting is cost..
.
So what's the step!
Re: 10 Weeks Of Node.js After 10 Years Of PHP by kingofthejungle(m): 7:44pm On Sep 08, 2016
is it possible to use node.js with a relational database like mysql
Re: 10 Weeks Of Node.js After 10 Years Of PHP by VenantCode(m): 7:56pm On Sep 08, 2016
KvnqPrezo:

Am learning PHP with w3schools and with some Apps and Ebook.
,
I don't wanna wait till am an expert..
I wanna be working on my project and learning also..,
.
I'm still battling to know what a framework is and how it works... I even researched on bootstrap today but don't know what to use it for...
.
Yes I decided to use PHP because I heard that python hosting is cost..
.
So what's the step!
The step is to breathe deep, be patient and give at least 7 weeks to complete the tutorials you are following in which 3 weeks into the materials you can start working on little side projects like a to-do note app. Think of it this way, if you start now to build your social network when you haven't had a good grasp of your tools. You will spend a VERY LONG TIME on doing the wrong things while if you take your time to learn it the right way you will discover that you would spend a SHORT TIME and doing the right thing. Which do you prefer, to spend 9 months doing wrong stuffs because you didn't have patience to study or to study well and spend just 1 month building it the right way

2 Likes

Re: 10 Weeks Of Node.js After 10 Years Of PHP by VenantCode(m): 8:01pm On Sep 08, 2016
kingofthejungle:
is it possible to use node.js with a relational database like mysql
Yes

1 Like

Re: 10 Weeks Of Node.js After 10 Years Of PHP by KvnqPrezo(m): 9:31pm On Sep 08, 2016
VenantCode:
The step is to breathe deep, be patient and give at least 7 weeks to complete the tutorials you are following in which 3 weeks into the materials you can start working on little side projects like a to-do note app. Think of it this way, if you start now to build your social network when you haven't had a good grasp of your tools. You will spend a VERY LONG TIME on doing the wrong things while if you take your time to learn it the right way you will discover that you would spend a SHORT TIME and doing the right thing. Which do you prefer, to spend 9 months doing wrong stuffs because you didn't have patience to study or to study well and spend just 1 month building it the right way
Thanks very much!
.
Would like to know about the to-do list...
Re: 10 Weeks Of Node.js After 10 Years Of PHP by VenantCode(m): 7:53am On Sep 09, 2016
KvnqPrezo:

Thanks very much!
.
Would like to know about the to-do list...
it's just a simple web app that allows you to add tasks to do and sorts them based on time and priority
Re: 10 Weeks Of Node.js After 10 Years Of PHP by KvnqPrezo(m): 10:49am On Sep 09, 2016
VenantCode:
it's just a simple web app that allows you to add tasks to do and sorts them based on time and priority
Thank you
Re: 10 Weeks Of Node.js After 10 Years Of PHP by larisoft: 12:14pm On Sep 10, 2016
Dan! Ten Years? Wow! How old are you? (Okay... I will pm you. so you tell me in private). Thats a lot of experience right there!!!

Wonderful write up!!!

In my own sentiments about languages (off the back of my hand): php is like a donkey (gets you where you need to be; but nothing really sexy), java is like a lion (forceful, can be slow, always strong, damn sexy, often an overkill though) c# feels metallic, (too inflexible and always an overkill), and javascript is just sweet. So flexible and yet so effective. It feels beautiful.

Now am just ranting...

Excellent write up Dan!

1 Like

Re: 10 Weeks Of Node.js After 10 Years Of PHP by Nobody: 2:46am On Sep 11, 2016
larisoft:
Dan! Ten Years? Wow! How old are you? (Okay... I will pm you. so you tell me in private). Thats a lot of experience right there!!!

Wonderful write up!!!

In my own sentiments about languages (off the back of my hand): php is like a donkey (gets you where you need to be; but nothing really sexy), java is like a lion (forceful, can be slow, always strong, damn sexy, often an overkill though) c# feels metallic, (too inflexible and always an overkill), and javascript is just sweet. So flexible and yet so effective. It feels beautiful.

Now am just ranting...

Excellent write up Dan!
Lol, Larry... The write-up is a Medium extract, I was thinking about Node and PHP, the MEAN stack and doing everything with one language.. Node is great, I see it rooting itself firmly amongst developers in the future... For now, we can all agree that even though Node is a better choice, PHP is still widely used.

My age, :-)... Well I'm old enough to be your Uncle, lol, that's all I can say.
Re: 10 Weeks Of Node.js After 10 Years Of PHP by larisoft: 6:03am On Sep 11, 2016
DanielTheGeek:

Lol, Larry... The write-up is a Medium extract, I was thinking about Node and PHP, the MEAN stack and doing everything with one language.. Node is great, I see it rooting itself firmly amongst developers in the future... For now, we can all agree that even though Node is a better choice, PHP is still widely used.

My age, :-)... Well I'm old enough to be your Uncle, lol, that's all I can say.

Got it, Dan. Reading up on the whole mean stack thingy right away.

(1) (Reply)

Best Mobile Application Development Companies In Nigeria / How To Build An On-demand Platform Like Uber Or Airbnb / My New Projects

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 43
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.