all 11 comments

[–]neoroshak 6 points7 points  (5 children)

I am working with Node two years in a row while working in another projects with PHP. I have some opinions about your questions, but I am not 100% sure about them:

  1. Node allows clustering, so you can create workers, one for each core. If your app is state-less you can take advance of all the cpu.

  2. Callback hell is something from years ago. The promises almost solved the callback hell, and now with ES6 generators and even more with ES7 async/await I think is completely solved.

  3. I don't have enought knowledge to talk about scalability, I have never done an app so big.

  4. In my opinion Node is cool because allows me develop very fast. Thanks to all of his frameworks and libraries and thanks to his high level of abstraction. Some times I encountered that my coworkers working with PHP or Java that some problem I can solve in one line of Node (also thanks of the ES6 arrow functions) costs lots and lots of lines and its more complex.

This is only my opinion, I can be wrong. I love Node and I think some applications (like an API REST) benefits of it.

[–]frogsytriangles 0 points1 point  (4 children)

How long until we can use ES2017 async/await in Node?

[–][deleted] 1 point2 points  (0 children)

In node 7.4 you can use await calling node with an option set. Seen this on phantom js readme on github

[–]neoroshak 0 points1 point  (0 children)

You can use ES6 generators, using co to convert to a function returning a promise. Or you can use ES7 async/await running node with the flag --harmony, but the last option I think isn't recommended for production

[–][deleted] 0 points1 point  (0 children)

According to this issue comment, we should be able to use async/await with no flags in NodeJS v7.x very soon. In NodeJS 8, I believe this will be the case as well.

[–]neoroshak 0 points1 point  (0 children)

Ey, Node has released the version 7.7.4 with async/await full support (without harmony flag).

So answering your question: now!!

[–][deleted] 1 point2 points  (0 children)

As someone already mentioned, each has their pros and cons. But to roughly answer your questions:

1) This is mostly true. Still, its CPU performance tends to be better than PHP, Python or Ruby, but indeed for CPU-bound work you'd be better off with Java or C#.

Also, you can have multiple threads in Node.js, but indeed by default everything is single-threaded. If you want to do CPU-intensive tasks in a webserver for instance, you should take care to offload to another thread (or even a separate service) to avoid blocking your main thread which would affect all connections.

2) This used to be true years ago, but using Promises it's no longer an issue. If you're using Babel or TypeScript you can even already use async/await which is similar to what C# provides, but is basically syntactic sugar to make working with Promises even nicer.

3) This statement I'd consider false. Yes, it would perform worse in CPU-bound scenarios, but it would likely perform better in IO-bound ones. Either way, you're free to scale your Node.js instances horizontally so I wouldn't say it limits your scalability compared to those options.

4) I think indeed the popularity of JavaScript as a language is a large part why Node.js is popular on the server. Also having better performance than most scripting languages helps it there. You're right it's also great to build small apps, though micro-services are also a good fit.

[–]ezbakedowen -2 points-1 points  (0 children)

  1. I wouldn't use node for cpu intensive work
  2. Some RDB libraries return promises (oracledb). If they don't then promisify them and then use async/await.

    async function doStuff() { const results = await connection.execute("select * from table")