Live data from Hacker News

Ask HN: Why Node.js and for which type of App?

news.ycombinator.com

41–49 of 49 posts

Re: Ask HN: Why Node.js and for which type of App?

#41

TL;DR: Apps that perform high I/O. For example, if your app is just getting data from a database and returning it to the user, 90% of your time will be spent: * Receiving the user's request (Network, IO) * Fetching something from the DB (Network, IO) * Returning the data (Network, IO) That's a good scenario for an event based system like Node.js. Try not to use node.js if you're CPU-bound: rendering images or PDF, pr…

The processing queue is kinda irrelevant, CPU bound tasks require lots of CPUs, and more CPUs if you want a processing queue.

Since Node / nginx are already processing queues it's kinda pointless to add another one.

Re: Ask HN: Why Node.js and for which type of App?

#42
post #17
post #13

Earlier quoted context omitted.

Thanks! So, you would use node.js just as a service to process data on the server side and not as a application for the desktop (with a gui)?

Typically Node.js is for high I/O web applications. Thanks to the wonderful asynchronicity of javascript (callbacks "let me know when this is ready/done") it's really wonderful for browser-based programs. However, there is growing discussion about using Node.js for desktop applications. Please see https://nodesource.com/blog/node-desktop-applications

Node also works well for desktop apps because it's got the run loop.

Desktop apps are insanely high frequency IO apps, basically, its an Input Queue reading the mouse / keyboard / touch screen and a run loop, which is exactly what node is, except node originally envisioned the input queue being web requests. And most desktop apps are single threaded on the UI.

Re: Ask HN: Why Node.js and for which type of App?

#43
One popular use that I'm not seeing a lot of other folks talk about here is using node to create build tools for web development.

Gulp and Grunt have been very popular as a way of, for instance, watching files and then minifying CSS an JS assets automatically while creating web pages in systems like WordPress that don't have built-in asset pipelines.

Re: Ask HN: Why Node.js and for which type of App?

#44

Reading all the comments here makes me wonder — Can Python (say, Flask) not be used for real-time communication (SocketIO, etc..) ? What is the difference between that and node.js ? I am still figuring out a lot of things about Python, and this is something I found very intriguing. What would the differences between an IM app written in Python using Flask and it's nodeJS clone be, to a user?

Yes python can, no flask can't.

https://github.com/eventmachine/eventmachine/wiki/EM-vs-Twis...

http://community.eveonline.com/news/dev-blogs/stackless-pyth...

Node.js is one of the few webservers built ground up async.

Re: Ask HN: Why Node.js and for which type of App?

#45
Node.js is in an interesting position. There is a lot of libraries and new ones are coming out at breakneck speeds. It's also a way for frontend developers to transition to backend tasks. And it gets a lot of mindshare at the moment, with MongoDB and microservices.

But in my opinion a lot of Node.js ecosystem is a lot of mismarketed features. Many developers doing backend services with Node.js actually think that it's the fastest thing available, even though multiple benchmarks, e.g. techempower, shows that it really isn't. And even more people seem to think that it is a way to do simple parallellism, so they won't have to understand threads and locking, which are really complicated stuff. But as many have said here, Node.js does not support threads, or parallelism without running multiple different processes. Which can be fine if you don't have any shared state between your processes. And with no parallelism in process, it is quite easy to actually block the event loop by running anything that is CPU and not IO bound. This can be a loop that is too long, too much math, or even parsing a JSON string without using streams. All of these can block the event loop, which means that no requests are going through that process while one request is parsin a JSON.

And even though there is a lot of libraries and frameworks for it. The quality is often really, really bad. As in invalid MD5 algorithm bad, etc. But there are also some gems such as Bluebird for promises, which makes the callback hell more easier to handle.

You will also face immature debug support, profiling and static analysis. You barely get any refactoring help from your tools, even though IntelliJ IDEA does quite a good job with basic refactoring and debugging. And you will have to spend time with handling odd bugs with no logs showing up on crash, or stuck processes when something has gone really wrong in the code, with no way of knowing (if you don't have DTrace) where the code is stuck.

But there are stuff Node.js seems to excel at. It is really quick for creating a simple REST service, feedback loop is really quick as the services restart almost immediately (at least when you don't use all the latest ES6 transpilers). And if you want to create isomorphic applications, where the server can render a Javascript site on behalf of the browser for the first request, or even successive requests for mobile use, there is no better platform than Node.js. And if you know that you will not do anything that is CPU bound, just IO bound stuff, you can still use any library available. Where for example in Java or Python, you would have to find specific libraries that support your chosen async IO framework.

I would use Node.js between a backend server done in a more robust ecosystem such as JVM, and the browser. Where Node.js gets the data from the backend and does it's magic with isomorphic React for the client.

Re: Ask HN: Why Node.js and for which type of App?

#46
post #11

Node.js is typically used for servicing web applications, but it has found some other surprising uses as well. There's a fairly sizable robotics (check out Johnny-Five) and drone community around it as well. The programming editor Atom by Github is also a "traditional" desktop app with Node.js at the core. In my opinion, Node's biggest advantage today is the absolutely massive module ecosystem that has sprung up arou…

PopcornTime is also a NodeJS app.

Re: Ask HN: Why Node.js and for which type of App?

#48
post #10

Node.js in itself is a wrapper around V8, the JavaScript engine of Google Chrome. It is used to execute JavaScript on the server for example to implement REST APIs. I would consider Node.js if you implement actual webbased software because you could take advantage of a shared codebase. If you want to display content on the internet there are more comfortable alternatives you could use. What you are probably looking f…

Hi there, thanks for your response. I programmed some Desktop Apps with Java and C#. And during some hackathons i used python+flask+nginx to implement a Web-Applications with a RestAPI on the backend. I was just curious for which type of application i can use node.js (since i didn't use javascript on the backend at all). Usually i used PHP, C# or Pyhton for the backend.. Is MS Windows 10 using node.js for their appli…

You can use Node in place of PHP or Python to implement a REST API backend. You can also use it to run scripts the same way you would use Python to do that.

Windows doesn't use node, they have their own JS runtime and a GUI framework that you can script with JS.

Re: Ask HN: Why Node.js and for which type of App?

#49
post #16
post #9

Node is a tool for running Javascript on the server. Your desire to use it will stem entirely upon your desire to write javascript to perform server side tasks. There are many languages and environments for running code on the server, so I personally have problems finding a niche where Javascript is the obviously better choice for these tasks. In my experience with it so far, it's "fast enough" for IO bound tasks (ro…

> Node is a tool for running Javascript on the server. Your desire to use it will stem entirely upon your desire to write javascript to perform server side tasks. Now that's often what people think of Node.js, but that's not really why Node.js is interesting. It's not just "JavaScript on the browser" . Instead, you should think of Node.js more like a JavaScript binding to `libuv`, which is the C library that provides…

Node is far from the first or only implementation of the reactor pattern in programming languages. There are many other, frequently more mature implementations which exist in most languages.

> Reasons why JavaScript was picked for Node.js: 1) It already dealt with events due to its usage in browsers and 2) a fast existing JIT runtime, V8.

Well, no, the original creator of Node just wanted non-blocking IO (which the frameworks he was using did not support), and (I'm editorializing a bit here) in the grand engineering tradition of re-inventing the wheel, he decided to use Javascript with v8 to create a whole new platform, instead of using an existing platform.

Post reply on HN