r/programming • • Apr 26 '16

Node.js v6.0 released

https://nodejs.org/en/blog/announcements/v6-release/
132 Upvotes

79 comments sorted by

39

u/hobozilla Apr 26 '16

This is excellent news - version 6 supports an impressive amount of the newer ESwhateverwhatever spec.

http://node.green/

16

u/not_an_aardvark Apr 26 '16

2

u/[deleted] Apr 27 '16

Pretty exciting stuff. I'm sure the React guys will really enjoy restructuring to go along with their spread syntax.

I like the default and rest parameters myself. I have a few helper functions that appear to take no args, but since I'm using the arguments array for variadic args the ...rest syntax would make it a lot clearer.

4

u/vivainio Apr 27 '16

React guys are using JSX, ergo Babel

6

u/[deleted] Apr 26 '16

Any tail call support yet?

9

u/smithclay Apr 27 '16

If you're curious about the performance improvements, https://benchmarking.nodejs.org has the latest numbers for v6 vs old versions.

26

u/oblio- Apr 26 '16

Say what you will about node, npm and the JS ecosystem, but it is rapidly maturing and together with the evergreen browsers the development setup is getting quite nice.

Sprinkle some Typescript or ES6, a decent selection of libraries and things aren't too shabby.

59

u/[deleted] Apr 26 '16

Call me when it's done

23

u/RiWo Apr 27 '16

Meanwhile I'll just enjoying mature Java libs, framework, and tools.

0

u/[deleted] Apr 27 '16

[deleted]

0

u/salgat Apr 27 '16

.NET is awesome and I love using it at work, but nothing beats setting up a nodejs app prototype in 10 minutes and hosting it for free on something like Heroku.

0

u/[deleted] Apr 27 '16

[deleted]

1

u/ThrowinAwayTheDay Apr 27 '16

But then you're using Windows and Visual Studio... :(

0

u/[deleted] Apr 27 '16

[deleted]

16

u/RiWo Apr 27 '16

Better than to have guess which type is this variable again?

9

u/[deleted] Apr 27 '16

Type? What is type?

3

u/[deleted] Apr 27 '16

Obj

0

u/[deleted] Apr 27 '16

[deleted]

9

u/balegdah Apr 27 '16

I don't understand why people say this. You can just check the type with typeof or use ===

Yeah, you don't really understand.

2

u/[deleted] Apr 27 '16

To explain a bit in a ELI5-fashion (dont want to patronize though)

We are talking about letting the computer tell you type errors before you even run the programm. This can save you some time.

typeof or === happen after you started your programm. So you can't save time by spotting it early.

11

u/oprimo Apr 27 '16

You know, I too used to look at the JS landscape and think "what a disaster". However I gave up the attitude a long time ago. JS is here to stay, like it or not. I can't see any other web programming technology coming close to JS in terms of pervasiveness. It's not going to be replaced any time soon. So, as good agnostic developers, we might as well celebrate any improvements to the Wild Wild West which is World Wide Web programming.

1

u/[deleted] Apr 27 '16

good agnostic developer is at risk of being compiled away

1

u/ledasll Apr 27 '16

just like Trump...

0

u/[deleted] Apr 27 '16

[deleted]

3

u/[deleted] Apr 27 '16

Yes but using which language? Seeing as how javascript is so ubiquitous, it's pretty clear that we need a javascript-to-wasm compiler.

4

u/[deleted] Apr 27 '16

To compile you need a semantic.

0

u/[deleted] Apr 27 '16

[deleted]

10

u/indigo945 Apr 27 '16

There are already a lot of languages that compile to Javascript, and most of them just work better as statically compiled languages than Javascript would because of static type systems. For examples, see Typescript, Elm, Haskell and C++.

6

u/weberc2 Apr 27 '16

It doesn't look bad. It would be cool if everything wasn't so JS centric, with decent concurrency support, and compilation to native binaries though. As is, I'm not sure what the appeal is for node over other VM languages. Maybe you could answer that?

0

u/oblio- Apr 27 '16

Dynamic language that is faster than Ruby or Python, for one.

It's not like those compile to native binaries or have decent concurrency support in their normal incarnations.

1

u/weberc2 Apr 27 '16

I know. I don't advocate for those languages either, for the same reasons.

14

u/ColonelThirtyTwo Apr 27 '16

Sprinkle some Typescript ... and things aren't too shabby.

That seems like a bad example. Having to write in a different (albeit similar) language to get something "not too shabby" doesn't really strike me as "mature".

5

u/[deleted] Apr 27 '16

One could argue gradual typing is all the rage to be fair. But funny how it's just forced as no one really knows wtf JS is doing.

1

u/Booty_Bumping May 02 '16

Mature =/= perfect. Java is considered "mature", but there's shitloads of room for improvement, beyond what's being introduced to Java in the near future. You see the same solutions to Java as you see in the js ecosystem: alternatives languages that all run on the same unified platform (the JVM or node.js.) If you tried to fix everything at once and turn js into a perfect language, it would no longer be mature as a platform.

Typescript/flow aren't really a different languages anyways. Since typescript is a superset of ES6, all the compiler has to do is strip out type annotations from the code. You're still writing pure ES6.

0

u/[deleted] Apr 27 '16

[deleted]

0

u/[deleted] Apr 27 '16

Is it an enterprise platform ?

1

u/Fingebimus May 10 '16

Do you like enterprise?

1

u/[deleted] May 10 '16

I like my enterprise webscale and ready for the big data

2

u/that_which_is_lain Apr 27 '16

Well it would rapidly mature, right? It can't get much worse.

5

u/renrutal Apr 26 '16

It's quite weird to see an OSS project doing press releases about new versions...

Anyways, here a link with the actual changes.

7

u/[deleted] Apr 27 '16

I want async/await, bro. And no, I'm not compiling node with microsoft's js engine just to get that.

4

u/simspelaaja Apr 27 '16

The TypeScript compiler already supports them, by emulating them using ES6 generators and promises.

1

u/newreddit0r Apr 27 '16

Isn't async/await actually just a syntactic sugar on top of the generators and promises?

1

u/simspelaaja Apr 27 '16

It is, even in C#. But ES7 might support it as a first-class feature.

1

u/vivainio Apr 27 '16

C# creates a switch-case state machine within functions to support async/await

5

u/[deleted] Apr 27 '16

Soon enough you'll just be able to fetch .NET/ASP Core 1.0 on your OS of choice and run Kestrel. Then you'll have the whole TPL library available to async/await your heart out.

1

u/Booty_Bumping May 02 '16

I don't think this is required. Typescript is written in pure MIT-licensed Javascript and will translate async/await syntax to generator.

If you want to stay away from Microsoft software, babel + flow is a good alternative.

-4

u/[deleted] Apr 27 '16

funny how monkey patching a language deficiency can -produce hype

0

u/[deleted] Apr 27 '16

[deleted]

2

u/[deleted] Apr 27 '16

Code Academy, Team Treehouse, Udemy, and Lynda are ones I often hear.

Recently picked up a good book as well: Web Development with Node and Express (4.0)

Since the majority of your Node backend work will likely be with Express+MongoDB, this book covers it. Both front-end style with template rendering as well as designing REST APIs that communicate using JSON.

0

u/[deleted] Apr 27 '16

[deleted]

2

u/[deleted] Apr 27 '16

Sorry if I confused you. Node is the runtime which runs JavaScript server-side. Express is a popular Node package which allows you to create web servers hosting HTML pages or REST APIs much easier. Given the nature of Node web development, most projects end up using Express.

MongoDB is a NoSQL database that stores JSON documents. It is the defacto standard in many Node/Express projects for storing data. It runs as a standalone service.

Many people use Mongoose (another popular Node package) to talk to MongoDB as well as defining their data models (called schemas).

This entire setup is often referred to as the MEAN stack: Mongo, Express, Angular, and Node. However, a lot of people have started migrating to Facebook's React framework instead of Angular.

1

u/ThrowinAwayTheDay Apr 27 '16

If he's trying to learn Node then throwing Express and Mongo into the mix is only going to confuse him more.

0

u/[deleted] Apr 27 '16

[deleted]

4

u/Categoria Apr 27 '16

Unlikely this will happen without upstream support from V8.

12

u/ruinercollector Apr 27 '16
  1. Concurrency doesn't mean threads.

  2. Parallelism doesn't mean threads.

  3. The idea is that you push computationally intense work (i.e. what you might actually want threads for) to another process and possibly even another machine or set of machines instead of bogging down your web server. This is pretty good practice even on a web platform that does let you spin up threads (e.g. ASP.NET)

  4. If you actually need threads and really really want this work in your web server process, you can write a C or C++ module for that particular piece.

5

u/[deleted] Apr 27 '16

While it doesn't have to mean threads, it typically does in one way or another. Even using node's built-in cluster library means spawning another worker process -- which has at least one thread.

Node is already concurrent, the event loop structure runs all of your code single-threaded... but IO code (like file and network access) are done by thread pool workers, hence the very asynchronous nature of Node.

As for being able to handle web requests more responsively, cluster works pretty well at that, which does as you mention... spawning up another process.

1

u/ruinercollector Apr 27 '16

but IO code (like file and network access) are done by thread pool workers, hence the very asynchronous nature of Node

Specifically by IOCP on windows, which is a lot more efficient than manually creating and locking up a thread from the pool during the entire wait.

1

u/[deleted] Apr 27 '16

[removed] — view removed comment

1

u/ruinercollector Apr 27 '16

Stop pretending that Node is the only one that can use I/O completion ports.

Are you serious? This entire comment chain has been me telling you to use IOCP even if you aren't using node, and you insisting that starting up a blocking thread to wait for IO was totally necessary and the right thing to do.

I even pointed you toward the built-in .NET framework methods that would use these, so that you could put in context of a platform you actually know and not one that you regularly fumble through talking out of your ass about on this subreddit.

It's embarrassing.

The only thing that's embarrassing here is watching you learn about concurrency for the first time while still attempting to maintain your usual condescension and arrogance.

4

u/[deleted] Apr 27 '16

Oh dear lord this is the GIL/Twisted drama all over again

2

u/kuikuilla Apr 27 '16

So just to get the request/response loop going due to being blocked by some CPU intensive function execution, I'm supposed to fork another process? Madness.

-2

u/[deleted] Apr 27 '16

[removed] — view removed comment

5

u/ruinercollector Apr 27 '16

Those threads I'm spinning up are in charge of sending information to other machines without making the result wait.

Yikes. I hope not. That's what IOCP are for. In .NET, use the built-in async methods and you'll get that without much need to think about it, but you should never be blocking a thread waiting for a network or file I/O result. That's just crazy.

You definitely don't need a thread to buffer and batch file writing.

2

u/[deleted] Apr 27 '16

[removed] — view removed comment

5

u/__kojeve Apr 27 '16

I don't understand how this comment is responsive to the parent comment at all. Node's async model may have problems, but batch file writing is certainly not one of them. The parent comment is making the clear suggestion that you don't need to do 1000 individual inserts, so I don't understand what you're suggesting.

3

u/[deleted] Apr 27 '16

[removed] — view removed comment

1

u/[deleted] Apr 27 '16

And the leaflet says it's non blocking

1

u/RazerWolf Apr 27 '16 edited Apr 27 '16

Node isn't capable of doing something similar. You can somewhat simulate it with a timer, but since it is single-threaded you [cores] instance of Node, each with its own log separate queue and timer.

Wait, what? You have a set of queues and a set of timers, which are checked every threshold interval (like every second or so). You store your log entries in queues and write them with async batch writes when they pass a size/time threshold.

This is even a more efficient solution because I'm not forced to use multiple threads to do this. What is this solution missing for you?

0

u/[deleted] Apr 27 '16

[removed] — view removed comment

2

u/Akkuma Apr 27 '16

If you use cluster to create processes they can all communicate with the parent process via message passing. The parent process now maintains 1 queue and 1 timer and is solely responsible for batch writes.

0

u/RazerWolf Apr 27 '16

You used the concept of threads when I explicitly mentioned not to do this. You know timers can exist without threads right? DispatcherTimer does this in WPF (https://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer(v=vs.110).aspx)

You need 24 queues, and 24 timers, and one node instance which will have a "dispatchTimers" called some point in its event loop.

→ More replies (0)

1

u/DigitalDolt Apr 27 '16

Still no multithreading.

Not that I use it often, but when I need actual concurrency or parallelism I like to have the option.

When I need parallelism I use Go. For everything else I use Node.

0

u/[deleted] Apr 27 '16

[deleted]

1

u/izuriel Apr 27 '16

Most often when engineering web services (making an assumption on what you've worked on) you probably never directly need to use threads; however, the framework you use or software you use undoubtedly uses them or other forms of concurrency. Just because you don't see the need doesn't mean there isn't the need.

The problem with Node is not "I can't run threads" it's when you flood the event loop. You can easily simulate this. Create a node HTTP server that hits a database and run SELECT 1; then run it through ab (or wrk) and you should see a massive spike in response times. That's flooding the event loop.

0

u/[deleted] Apr 27 '16

[deleted]

1

u/izuriel Apr 27 '16

I didn't say that threads are immune to saturation. I said Node.JS's event loop is way to easy to over saturate because it pulls one event down and while that's working all other events are blocked.

Try running the exact same test against a threaded web framework and I guarantee you that simple example bombs on Node harder than any other. If you think the event loop is competitive to threads then it's clear you have yet to be bitten by it.

0

u/[deleted] Apr 28 '16

[deleted]

1

u/izuriel Apr 28 '16

You say it's "apple to oranges" but I'm not sure you understand most of what you're talking about.

a more accurate comparison would be to a cluster of node processes

It's built using node, with clusters of processes.

At no point did we need threads

(emphasis mine)

First you declare that a multi-threaded process should be compared to multiple Node processes. Makes sense, Node's cluster library is the best way to achieve a "threaded" Node system. That would be more fair.

Then you say you built some massive system without threads, but needed clustered processes and then declare you never needed threads?

Either clustered Node processes hosting the same program equate to a single threaded process running a program or it doesn't. You either think they're equivalent or you don't.

I don't care what you've built. We're not here comparing résumés. Whatever you've built, whatever the community has built with Node doesn't change the fact that it's very easy to flood the event loop. So easy that you'd be insane to run a deployment for a lightweight service (several thousand hits/second) on a single Node process. The reason is because the event loop is out of your control, and as soon as one event queued up backs up you have a waterfall effect from there on out. So yea, of course you want to cluster. Eight, or sixteen event loops are better than one.

Threaded systems max out on requests too, but they suffer in different way. Some threaded systems mix both concepts. Go's concurrency model uses OS threads for goroutines but will swap out goroutines or pass them between thread contexts when one blocks and another can run. This allows you to have, some small number of threads with large numbers of goroutines as the runtime tries to maximize processor time.

Other solutions are more straightforward, in most languages there is a threading concept and you simply leverage threads for work. Most web servers (which you'd run in front of Node for static content and as a gateway) like Apache and Nginx are threaded applications.

The whole point of my comment was exactly as I stated it:

The problem with Node is ... when you flood the event loop.

Which is a perfectly valid point. It can't be refuted because it is a problem. It's the reason the cluster library came to be! Boy running a Node server before then was not a pleasure, you had to dig around for node services to provide the feature, then make sure your master process is running behind a forever application which is then, most likely, watched by an upstart job -- at least that's what you used to do. There are more fancy tools now so you can run your Node applications with some peace of mind.

In the meantime, there are plenty of other platforms that don't suffer from the issues that a single threaded event-loop system create for itself and with those platforms one doesn't have to find additional tools to combat those issues.

As a final note, I'm not here to deliver to you benchmarks galore. I provided a sample that demonstrated my point and that's sufficient. You started in with the argument about how wrong I was and so the burden of proof is now yours. I'd advise you do some research on further understanding about Node's event loop.

0

u/[deleted] Apr 28 '16

[deleted]

1

u/izuriel Apr 28 '16

I'm having a really hard time finding the article I really want to reference. I saw it on /r/golang a while back. It was post from an engineering team (or engineer?) from a company that would receive daily spikes of requests.

Each of these requests required multiple fetches from S3, and given that AWS has no bulk fetch from S3 API the files had to be requested individually. So millions of incoming requests, each fetching multiple S3 files each they ran into a problem. Before I explain, the bottleneck was S3, not their system. But this bottleneck created a unique issue since their system was built in Node.

They ran multiple node servers and each of those were clustered of course but the sheer volume pretty much meant that traffic was hitting every single process they ran. The S3 bottleneck meant that requests hit the event loop and clogged them which led to timeouts, long wait times and an overall poor experience.

Their solution was re-engineer this piece in Go (obviously if it was posted to /r/golang) which handled the load quite gracefully with fewer resources (servers/processes/memory/CPU) overall.

The moral, and my point is, Node's event loop is a huge bottleneck that seems to be widely ignored or passed off. I acknowledge that it doesn't fail for all use cases. But node supporters defend it as a genius solution.

I didn't say I didn't need concurrency, I said I didn't need threads. I used processes instead.

The reason why I took issue, and of course caused you to comment about it is quite simple. Node as a single process was designed (originally) to function as a single process. You weren't supposed to need threads because it's amazing. Threaded programming is concurrent programming. So if you're eschewing threads in favor of the event loop you're declaring no need for concurring programming. It became quite clear over time that having no concurrency model was never going to work and thus entered the cluster utilities in the standard library. So I compare Node to a platform that supports threads (or concurrency models, since Erlang uses processes too) because the event loop creates unique problems that these other systems are immune to by their very nature of not having one. I'm including the ability to cluster, and host on various servers as well. I'm not attack Node so much as I'm expressing a distaste for the weaknesses that the event loop creates.

If it makes you feel any better I dislike EventMachine for Ruby for the exact same reasons. Although Ruby has threading it's standard implementation has a GIL which is a whole 'nother thread.

As a side note, I first started building applications with Node in 2011 when it was really young. I've watched it grow over the years and I occasionally test it against that "simple benchmark" to see if they've been able to combat floods like that but it's always prone to the same problem and that's not something I'm interested in when using a platform. I get that clustering alleviates this.