r/javascript • u/vzhou842 • Apr 23 '19
Introducing Node.js 12
https://medium.com/@nodejs/introducing-node-js-12-76c41a1b3f3f91
Apr 23 '19
ES6 Module Support!
47
u/jsnoobie Apr 23 '19
No more red squiggly line in vscode under the “re” on my require statements!
I was a little ocd about that one
23
u/tanguy_k Apr 23 '19 edited Apr 23 '19
It's still behind a flag (
--experimental-modules) + you need to add"type": "module"inside your package.json.See https://medium.com/@nodejs/announcing-a-new-experimental-modules-1be8d2d6c2ff
17
Apr 23 '19
Yes, but they expect to remove the need for the flag during the development of this version (before it goes LTS in October).
8
u/ShortFuse Apr 24 '19
Do I still need to use Michael Jackson Script file extension?
I've been using the
esmpackage, but I would like to be able to remove the dependency?3
7
3
33
22
21
u/QW4K Apr 23 '19
Can't wait to try async stack traces. It's so weird that we didn't have them for that long in async language like JS.
Last time I tried it (on experimental build) it didn't really work for me and in the end, I used bluebird debug mode I hope it's fixed by now.
15
u/NoInkling Apr 24 '19
List of some of the new ES features/APIs now available thanks to V8 7.4 (compared to 7.0 in Node 11):
Class fields (both public and private)
Object.fromEntriesString.prototype.matchAllSome new
IntlAPIs
18
84
u/twomousepads Apr 23 '19
The Node.js foundation can't afford to put their blog anywhere other than Medium?
24
u/silveredge7 Apr 23 '19
Don't know why you were downvoted, what your'e saying is true.
-19
Apr 23 '19
No it isn't. The Medium website is shite on mobile, it's true... but to say that they use it because they 'can't afford' any other option? Patently untrue. Do you see how these things are different?
10
u/eggn00dles Apr 23 '19
there is absolutely zero reason for node to have their company announcements on a third party site. if medium goes down, so does the node blog? there's a better option, it costs more, and node isn't willing to spend that. as an end-user whether they can 'afford' it or not is semantics.
7
u/takaci Apr 23 '19
Also medium is pushing the paid content really aggressively recently. It's not a nice user experience
5
3
u/showMeNiceCode Apr 23 '19
What mobile do you use? It works just fine for me.
9
Apr 24 '19
Wait, some people actually use medium on mobile?!
5
1
u/SupremeLisper Apr 24 '19
Well, I never had it that worse. Without ublock-origin it's painful browsing the web on mobile let alone desktop.
4
u/coloured_sunglasses Apr 24 '19
What advantage would that provide them?
9
u/RnRau Apr 24 '19
Medium is an awful blogging platform.
4
1
u/icanevenificant Apr 24 '19 edited Apr 24 '19
Why is it awful? Haven't seen that sentiment before so I'm genuinely curious.
3
u/RnRau Apr 24 '19
Have you tried navigating comments and responses? Tried copying some information from the comments without causing a page refresh and navigating away from the article?
2
1
u/tybit Apr 28 '19
It would mean their readers aren’t bugged to pay medium money.
I have no interest in paying money to medium because a lot of the blog posts I’ve read have unfortunately been hosted on medium and they now feel I owe them something.
1
u/THICC_DICC_PRICC Apr 24 '19
Eh Jeff Bezos talked about his dick pic drama there I guess money isn’t really the issue there.
12
u/morficus Apr 24 '19
Now if only AWS Lambda could offer a newer version of Node.js, that would be great
6
1
2
u/mubaidr Apr 23 '19
So what's the difference in use cases between workers and child processes or forks?
2
Apr 24 '19
So glad they listened and made the .mjs extension optional instead of mandatory for ES module support! Just adding "type": "module" to your package.json is enough now to opt in.
3
u/carlos_vini Apr 23 '19 edited Apr 23 '19
"Async stack traces" is really nice.
https://v8.dev/blog/v8-release-73 is broken (ERR_CERT_COMMON_NAME_INVALID) to me.
1
-13
u/vivainio Apr 23 '19
While Node.js already performs well with the single-threaded event loop, there are some use-cases where additional threads can be leveraged for better results.
...and to think other runtimes have wasted decades supporting multiple threads
11
u/cm9kZW8K Apr 23 '19
...and to think other runtimes have wasted decades supporting multiple threads
The lack of threading is one of the great features of JS, and a big part of why it won out over other languages.
14
u/ryeguy Apr 23 '19 edited Apr 23 '19
and a big part of why it won out over other languages.
I don't think this is true. When people say that JS's concurrency model is superior to threads, they mean that having everything be async by default is superior to having to use threads to do that.
4
u/cm9kZW8K Apr 23 '19
Having the whole ecosystem being non-blocking is just superior - it means there are no landmines hiding away. When using C++ to do async code, especially when you have a selection of 3rds party code, you are often timebombed by some path that ends up calling a blocking syscall. JS is largely free of that.
Threads also dont have very many valid use-cases. Especially when you can just as easily fork a separate process on a modern linux, there just arent many times where a thread is the right choice to do something. Other than making up for the weaknesses of local hard-drive IO, async style programming has largely displaced threaded programming because its significantly more efficient and less buggy.
it turns out that there are nearly no modern uses for threading that arent better solved with other techniques.
8
u/ryeguy Apr 23 '19
But lack of threads has nothing to do with async. Node could still have async-everything and threads. That's the point I was trying to make - it's not the lack of threads that's nice, it's the nonblocking nature of everything.
Threads are still very relevant when it comes to working on cpu bound tasks in a way that needs access to shared data. Again, this isn't related to async or not. I'm not saying Java-style thread-based concurrency is better than node's. I'm saying there's a world were we could have both, and it would give us more flexibility.
1
u/cm9kZW8K Apr 24 '19
Threads are still very relevant when it comes to working on cpu bound tasks in a way that needs access to shared data.
Right; if you need access to a large heap, cannot factor the data structure into shards, cannot defer to the OS via disk/disk cache, cannot isolate the access from the processing, and have minimal need for write mutexing, and for some strange reason cannot mount the data as SHM ; then maybe there is a case where direct access to heap RAM to perform cpu bound operations is the best option.
IME its very rare and the vast majority of times isolation of the critical sections which actually needed the heap and surface them over an api, or else splitting the problem into equal sized tasks over separate processes are better options.
Node could still have async-everything and threads.
I think the two are tied hand in hand; having access to thousand of libraries and vendor code where you automatically know there will be no threading and no blocking is exactly why you can count on async everything.
If threading was an option, over time people would elect to use it (for the wrong reasons) and it would start to proliferate through the ecosystem.
For what JS is, its better, systemically, that threads are not part of the language, imo.
Do you have an example problem in mind where it is the best solution?
Most problems in the space eclipse the space available in RAM anyway, so you end up back with multiple process. Its just a real strange corner case to need them, that I just havent found it. Even before working in JS, i had a flat no threading criteria for the team unless they could justify why it was the best case. and over 10 year, the only cases where workarounds for OS calls which blocked.
1
u/Randdist Apr 24 '19
Threads are absolutely needed when you need to load and then parse large binary files. Loading can be done in parallel using the native calls but the parsing would block the main thread for a long time, or severely reduce responsiveness even if you split the parsing in multiple smaller batches.
Threads are vital for certain sets of responsive applications.
1
u/cm9kZW8K Apr 24 '19
Threads are absolutely needed when you need to load and then parse large binary files.
Other that avoiding the kernel flaw around O_NONBLOCK on local drives, there is no need to thread read syscalls. Node conveniently has built in threads for those, so reading in the bytes works async out of the box.
split the parsing in multiple smaller batches.
If the parser yields often enough, it doesnt have to impact responsiveness at a. For example: replacing tight loops with Promise.each ensure granularity. if your file parse involves heavy CPU transformation of data beyond just reading into RAM, then you can pipeline that in via a separate process.
Threads are vital for certain sets of responsive applications.
Threads were vital to work around flawed OS's which cannot fork() well. If you are finding them vital today, I think there is a problem with the structure of your code.
I regularly deal with this issue, both with fork()s for heavy cpu transforms and async code for simple heap building, and I would consider a threaded approach to be a bug.
0
Apr 24 '19
[deleted]
1
u/ryeguy Apr 24 '19 edited Apr 24 '19
Yes, I'm aware. What's your point? Are you going to argue that js is popular because it doesn't have or need synchronization primitives? That doesn't hold, how do you explain Go's success?
-1
u/AwesomeBantha Apr 24 '19
Actually massive PogChamp, this will make a project I'm working on with a backend and a frontend in the same repo much cleaner...
-1
-10
98
u/Earhacker Apr 23 '19
I paused for a moment to consider how "Faster await" would work and I think I had a stroke.