Why I ❤ Node.js

sakulstra
8 min readFeb 11, 2016

--

I developed with CakePHP/Laravel for the most time of my web career and just recently switched to node.js(more specific Meteor). I also used drupal and django for some time - I even had to work with JSP and RoR. In the past I had to work with Mysql, MSaccess, MariaDB and currently I am working with MongoDb. I’m no one who’s really excellent in one of these (languages).

Yesterday I saw this post on crater.io. It now has something around 3,5k recommends so there has to be some value in this, i thought and started reading.

It isn’t.

It almost sounds like satire. Perhaps it is. Hopefully it is.

I don’t want to offend the writer. Perhaps he had just a bad day… rainy weather, an evil boss or vegan food ;). So this wont be a “troll-back” post. There’s no sense in convincing a specific person. Do what you want. I write this as an opinionated experience i made with node and it hopefully opens the eyes for at least someone.

Spreading bad mood isn’t something useful for anyone.

Node didn’t went to shit in 2015

Io.js and node.js merged back. More and more small libraries created node packages. You can now add “chartist”: “^0.9.5” to your package.json and have all the files in your modules folder as soon as typing npm install. Keeping versions updated in php was like hell. We even used versioneye to keep track of updates so we don’t just miss them.

…so for me this is good news nod bad ones.

NPM

Coming from PHP I can’t really get this argument. Node did something, some other languages really needed but never really got. A dependency manager. Okay, PHP has composer since a few years and C got Biicode (which just died as soon as I know). So other languages have to hack around something, which is build in node natively.

NPM is something other languages are jealous of. Nothing to bad.

I won’t try to argue against the “worst fucking language” argument. That was just for click baiting I think. Why to do this on a platform like medium? Don’t really get it - you don’t get paid for clicks dude.

I worked with a lot of languages, even had to code in assembler, cuda, opencl and racket. I don’t see why node should be worse than some of them… especially php?

…okay, this is useless. So I’ll just explain why I like node.js.

How to create a website on my local machine?

  1. Install meteor: curl https://install.meteor.com/ | sh # there’s an executable for windows
  2. type: meteor create coolname
  3. type: meteor

That’s it… everything is up and running! And I didn’t even had to kill my system with nginx/apache or even xampp on widows.

You want to build an apk for android out of you website code? meteor add-platform android

Want user authentication? meteor add accounts-ui accounts-password

… (could be continued, if your interested: read the Meteor guide) Works also with npm packages from 1.3 on.

React is awesome

React is a tad complicated at first, but no one forces you to use it. I wouldn't use it myself for production apps - it’s still evolving fast and not even 1.x, yet. But a virtual dom isn’t something bad at all. In fact it’s something really good!

Native vs. VM

(…)The DOM is slow. It is native, written in C++ and yet it is slow as hell because of the complexity that it has to implement.

console.dir(document.createElement('div'));

and see how many properties an empty div element that is not even attached to the DOM has to implement. These are only the first level properties that are “own properties” ie. not inherited from the prototype chain:

align, onwaiting, onvolumechange, ontimeupdate, onsuspend, onsubmit, onstalled, onshow, onselect, onseeking, onseeked, onscroll, onresize, onreset, onratechange, onprogress, onplaying, onplay, onpause, onmousewheel, onmouseup, onmouseover, onmouseout, onmousemove, onmouseleave, onmouseenter, onmousedown, onloadstart, onloadedmetadata, onloadeddata, onload, onkeyup, onkeypress, onkeydown, oninvalid, oninput, onfocus, onerror, onended, onemptied, ondurationchange, ondrop, ondragstart, ondragover, ondragleave, ondragenter, ondragend, ondrag, ondblclick, oncuechange, oncontextmenu, onclose, onclick, onchange, oncanplaythrough, oncanplay, oncancel, onblur, onabort, spellcheck, isContentEditable, contentEditable, outerText, innerText, accessKey, hidden, webkitdropzone, draggable, tabIndex, dir, translate, lang, title, childElementCount, lastElementChild, firstElementChild, children, nextElementSibling, previousElementSibling, onwheel, onwebkitfullscreenerror, onwebkitfullscreenchange, onselectstart, onsearch, onpaste, oncut, oncopy, onbeforepaste, onbeforecut, onbeforecopy, webkitShadowRoot, dataset, classList, className, outerHTML, innerHTML, scrollHeight, scrollWidth, scrollTop, scrollLeft, clientHeight, clientWidth, clientTop, clientLeft, offsetParent, offsetHeight, offsetWidth, offsetTop, offsetLeft, localName, prefix, namespaceURI, id, style, attributes, tagName, parentElement, textContent, baseURI, ownerDocument, nextSibling, previousSibling, lastChild, firstChild, childNodes, parentNode, nodeType, nodeValue, nodeName

(…)

Meanwhile, these are the first level properties of a fake-DOM div in React:

props, _owner, _lifeCycleState, _pendingProps, _pendingCallbacks, _pendingOwner (…)

So the answer to the question: Why rebuilding stuff that works?

Evolution

No one wants to use windows 95 any more. But some people feel offended when you tell them the stuff they use is outdated by years.

Speed is always an argument. When a page loads to long people will close the tab. So speeding up some parts of an application with react can totally make sense.

But Golang, Elexir (Phoenix) is so much better/faster! Perhaps it is, but for me it’s more convenient to use javascript everywhere. Actually I really liked using PHP inside html (even if i hated PHP as a language) for the frontend and think underscore isn’t that comfortable in comparison - hell, there is no if/else O.o - but now I don’t have wrap my head around when switching between frontend and backend. Not even when switching between static frontend and frontend ui animation stuff. This is a statistic I can’t proof, but for me the time switching between files to understand contexts has been dramatically reduced. This is an advantage I don’t want to miss. If you like golang more? Go for it. It’s from google. The same geniuses that made polymer-project and web components. I think this will get more important in the future.

Testing is another argument. I don’t know how much this counts nowadays, but frontend testing is kind of impossible when using “old languages” (At least this was the fact a few years ago).

But no one forces you to refactor anything to react? When your users are happy, you don’t have to change anything. We sill use MSaccess for some stuff, because we are to scared of bugs we face when porting we didn’t know about. Some day we’ll get into problems with this, but today everyone is happy with it.

Real-live experience

Just recently I had to implement a interface which serves a chart for real-time data with a pretty high frequency. I wouldn’t say it’s impossible to implement something like this with other languages - but it’s definitely not that easy. I needed more time for writing the post than writing the actual application. npm install and everything was ready (okay 10 minutes googleing the right packages).

Is node.js perfect?

So is node.js or any of the platforms like meteor built on it perfect in any ways? No. There’s a lot of cool stuff missing that RoR, CakePHP and older framework already have. Node is still a baby language and the frameworks built on top of it are not even born in comparison to the dinosaurs out there. It evolves a lot faster than them and is far ahead in a few topics, but also still behind in some cases, too. I for example miss the cake bake shell in Meteor, but I hope something similar comes with Mantra in the near future.

Conclusion

People take language selection to religious. If you don’t like it - don’t use it. Spreading bad mood isn’t that cool as it seems, when realizing that the languages I currently use aren’t that new any more. There’s no need to change the stack, as long as the development speed you have -due to experience- weights up the advantages you would have taking the shiny new language. If you start learning a language node.js isn’t that bad after all. When handling live data, reactiveness or universal apps you don’t want to hack this into a dinosaur, when on the other hand you could simply take something bringing all this built in natively.

Thats not a death sentence for other web languages.

When I had to manage a relational database with a lot of forms or a site which has to be SEO optimized to the max i would probably still go with django. Not because it’s not possible with node, but it’s most likely easier with something else. No need to cut down a tree with a fork.

Disclaimer

I’m no web dev anymore. Most of my paid time I work as msp430 developer in C. So this is just the opinion of someone who sometimes has to create visual data analysis for real time data or some web apis for hardware interfaces - no full time webdev at all.

Appendix

#1 Problems using windows

I think bad windows support is no real problem at all. You would probably never deploy a node.js, python or even php application on a windows machine - so why to do development there? Just imagine you had to use wkhtmltopdf, graphicsmagic or some other command line tool - these are pretty common tools for generating pdfs or manipulating images - you don’t want to do this on a windows machine. If you really need windows for whatever reason, use a VM. Caring about multiple OS is always a maintenance problem - especially for cli-heavy stuff like Node.js/Meteor windows isn’t really suited.

But your right - If something states is has windows support and it actually hasn’t: it’s disappointing.

#2 Praise Meteor/MDG, not Node.js

It seems like some people think MDG did some magic with node. Actually they did. So node is “shit” and MDG is awesome. They are partially right.

As I said node isn’t perfect. For example the praised npm didn’t work out for MDG so they built their own package manager… which is a wrapper around npm. What?! Yep, npm wasn’t user friendly enough when the Meteor guys started developing their awesome stuff so they managed to make it usable. With 1.3 they seem to got to the conclusion that npm has gotten better, so they integrated it. Now you can use both, npm and the meteor npm wrapper.

What to learn from this? What to do, if it’s not working like it should?

Go fork yourself.

If your solution is better, do a PR and with some luck it gets better for everyone. Things like that aren’t unique to Meteor/Node. PHP didn’t have namespaces and was freaking slow (sadly still is) but people found ways around it and with php7 - yeah, this was evolving really slow - caching gets baked into the core.

Saying node is shit, and MDG is the one to praise is kind of unfair. Drupal for example is built on cowpat, but is actually really near to an (old) bagel now. So to be fair, Meteor is built on dirty candy and just slowly transforms into a cake.

--

--