News for hackers. Stuff that matters.
Re:Node v6.6.0 by STRiDEX on Thursday September 15, 2016 @05:25PM (#12509937)
Been waiting for promises: Unhandled rejections now emit a process warning after the first tick. I'm not sure how useful the warning is though.

Now using node v6.6.0 (npm v3.10.3)

$ node

> Promise.reject()

Promise { <rejected> undefined }

> (node:85928) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): undefined

Re:Node v6.6.0 by danneu on Thursday September 15, 2016 @06:55PM (#12510547)
This will save a lot of time across the Node ecosystem.

Forgetting to handle rejection is probably the most common error I see when people post Promise snippets in #node.js. Silent failure is so deadly. "Why do my requests hang?"

Re:Node v6.6.0 by jamesrom on Thursday September 15, 2016 @08:28PM (#12511054)
Sometimes you just want an error to bubble up and be caught above. There's absolutely no reason to catch every rejection in the scope where the promise was created.
Re:Node v6.6.0 by danneu on Thursday September 15, 2016 @08:59PM (#12511189)
Yeah, looks like it just checks on nextTick, so it only warns when you don't attach a handler synchronously. Versus warning only if it's unreachable (like on garbage collection).

Though it does emit another message when rejection is handled asynchronously.

    > var p = new Promise((_, reject) => reject('lol')) \
      setTimeout(() => p.catch(() => console.log('handled')), 0)
    UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 5): lol
    PromiseRejectionHandledWarning: Rejection handled asynchronously (rejection id: 5)
Consolation prize?

Fortunately, most of the run of the mill promises I can think of off the top of my head get rejection handlers attached synchronously, like in upstream middleware. I might be drawing a blank, though.

Re:Node v6.6.0 by tlrobinson on Thursday September 15, 2016 @06:58PM (#12510564)
It will at least print the rejection value coerced to a string ("undefined" in your example), but line numbers would be nice.
Re:Node v6.6.0 by Noseshine on Friday September 16, 2016 @12:29AM (#12511830)
What will it give you what 'unhandledRejection' [0] doesn't?

I don't mind that it also emits a warning, but AFAIK you could already get that information by subscribing to this more specific event?

[0] https://nodejs.org/dist/latest-v6.x/docs/api/process.html#pr...

Re:Node v6.6.0 by _greim_ on Friday September 16, 2016 @12:50AM (#12511915)
It will hopefully remind you that you forgot to register that event.
Re:Node v6.6.0 by michaelsbradley on Thursday September 15, 2016 @05:28PM (#12509959)
It seems generators and trampolines involve considerably more CPU overhead in the 6.x series vs. 5.x, while tail calls are now fully optimized and/or the default stack limit has grown considerably.

Try running the following script with v5.12.0 and again with v6.6.0:

https://gist.github.com/michaelsbradleyjr/d1b104137e8e00468d...

   node --version && node --use_strict ./mutrec_vs_tramp_vs_gen.js
Re:Node v6.6.0 by _greim_ on Friday September 16, 2016 @12:40AM (#12511873)
> tail calls are now fully optimized

Can't remember where I heard this, but I'm given to understand they aren't optimized, just allowed. As in, recursive calls from tail position won't be super-fast or anything, they just won't blow out the call stack. Optimization may or may not be added to the engine at some future date.

Re:Node v6.6.0 by jnbiche on Thursday September 15, 2016 @09:11PM (#12511230)
> while tail calls are now fully optimized and/or the default stack limit has grown considerably

That is great to hear. Now we can finally start really doing functional programming in JS. Too bad about the generators, though.

Re:Node v6.6.0 by michaelsbradley on Thursday September 15, 2016 @09:34PM (#12511324)
Well, I'm not sure which one is the case, sorry to say (TCO or bigger stack limits, or both). I was only taking a guess as to why the mutual recursion example works for very large values in node v6.x but not in v5.x. But yes, if tail call optimization is guaranteed, then functional programming patterns can certainly shine the brighter for it.
Re:Node v6.6.0 by sciurus on Thursday September 15, 2016 @06:03PM (#12510211)
Not much to see here. The release next month will be more notable; that's when the 6.x series becomes an LTS.

https://github.com/nodejs/LTS

Re:Node v6.6.0 by gkya on Thursday September 15, 2016 @06:18PM (#12510318)
The last time I checked node it was 0.12.* . How did it become 6.* in a couple years time?
Re:Node v6.6.0 by bdcravens on Thursday September 15, 2016 @06:22PM (#12510339)
A bunch of folks unhappy with Joyent's progress on node forked it into io.js, they had an aggressive release schedule, and then when the 2 project reunited, they chose to use io.js's versioning. (io was at 3.3; the new unified release was 4.0)
Re:Node v6.6.0 by untog on Thursday September 15, 2016 @06:28PM (#12510367)
It now uses semantic versioning: http://semver.org
Re:Node v6.6.0 by Touche on Thursday September 15, 2016 @06:20PM (#12510323)
They adopted a different versioning system.
Re:Node v6.6.0 by angersock on Thursday September 15, 2016 @10:10PM (#12511441)
They adopted the correct versioning system. The old one was rubbish.
Re:Node v6.6.0 by bitroliest on Thursday September 15, 2016 @05:27PM (#12509948)
Looking forward to node 6 being put in LTS later next month, we'll consider moving from node 4 then.
Re:Node v6.6.0 by afarrell on Thursday September 15, 2016 @06:03PM (#12510212)
If you use the Anaconda distribution of Python, you can install this with `conda install --channel amfarrell nodejs=6.6.0`
Re:Node v6.6.0 by kough on Thursday September 15, 2016 @07:00PM (#12510578)
This is sort of an insane suggestion. Why use a Python distribution to install Node?
Re:Node v6.6.0 by rawnlq on Thursday September 15, 2016 @07:09PM (#12510618)
It's pretty sane if you are also a python programmer. I personally can no longer keep track of how I installed/set up my environments and would much prefer everything under a single package manager (instead of pip, easy install, eggs, virtual env, apt-get, nvm, npm, docker, brew, macports, etc etc).
Re:Node v6.6.0 by rnhmjoj on Thursday September 15, 2016 @10:47PM (#12511533)
That's exactly what Nix [1] tries to accomplish. You should look into it. I have been using it for about six months and has worked very well for me, especially for haskell and python development.

[1]: http://nixos.org/nix/

Re:Node v6.6.0 by afarrell on Friday September 16, 2016 @04:10AM (#12512581)
I came across it back in 2014 and have been meaning to check it out since. Do y'all have a how-to-build-a-package walkthrough?
Re:Node v6.6.0 by rnhmjoj on Friday September 16, 2016 @08:02AM (#12513392)
The Nix manual is a good start: http://nixos.org/nix/manual/#chap-quick-start Then there are a lot tutorial about setting up a development environment for a particular language. See:

go: http://lethalman.blogspot.it/2015/02/developing-in-golang-wi...

haskell: https://ocharles.org.uk/blog/posts/2014-02-04-how-i-develop-...

python: http://datakurre.pandala.org/2015/10/nix-for-python-develope...

node.js: http://sandervanderburg.blogspot.it/2014/10/deploying-npm-pa...

I recommend reading Luca Bruno's blog for learning Nix internals and more advanced topics.

Re:Node v6.6.0 by gcr on Thursday September 15, 2016 @08:19PM (#12511024)
Conda is not a python package manager. It's just a package manager. You can keep all kinds of software in your home folder.
Re:Node v6.6.0 by afarrell on Friday September 16, 2016 @03:46AM (#12512516)
The biggest advantage for me is using conda environments to avoid having to install everything globally. That way if I want to switch back and forth between python2 and python3 or different versions of node, I can just do `source activate foo`.
Re:Node v6.6.0 by inlineint on Friday September 16, 2016 @05:49AM (#12512877)
For Node.js you can use NVM for the same purpose. It is specially suited for handling multiple node verions and installs everything to user's directory.
Re:Node v6.6.0 by mkoryak on Friday September 16, 2016 @08:04AM (#12513401)
Nvm sucks at npm link. If you use npm link and nvm things will break. Thats why you should use n instead.
Re:Node v6.6.0 by afarrell on Friday September 16, 2016 @12:31PM (#12515184)
yea, but you can't also use it for installing a particular version of MongoDB or Postgres.
Re:Node v6.6.0 by inlineint on Saturday September 17, 2016 @02:44AM (#12519449)
Yes, it's a valid point. That's said I personally prefer Docker for installing databases of all kinds on my development machine.
Re:Node v6.6.0 by gcr on Thursday September 15, 2016 @08:18PM (#12511023)
Thanks for packaging node for Conda, amfarrell! It's nice to see non-Python packages in Conda.
Re:Node v6.6.0 by afarrell on Friday September 16, 2016 @03:53AM (#12512538)
Yea, I wish there was more of this, but the limiting factor is walkthrough documentation for folks who are new to packaging to learn to create and debug conda packages. I have long wanted to write an such and intro tutorial, but only recently succeeded in learning how to build packages and haven't had the time science.

The real problem is that creating a good intro developer experience takes sustained skilled time. I'm right now working on a similar project at GoCardless and we've got 3 engineers and a designer focused almost full-time on writing, designing, and user-testing our API tutorial. The Conda community would either have a patreon to sponsor someone to work on it, or convince a company to do that.

Re:Node v6.6.0 by dmh2000 on Thursday September 15, 2016 @06:24PM (#12510351)
dang it i just installed 6.5 this morning
Re:Node v6.6.0 by tlrobinson on Thursday September 15, 2016 @06:59PM (#12510576)
I recommend nvm on your dev machines.

    $ nvm install 6.6.0
    Downloading https://nodejs.org/dist/v6.6.0/node-v6.6.0-darwin-x64.tar.xz...
    ######################################################################## 100.0%
    Now using node v6.6.0 (npm v3.10.3)
    $ node -v
    v6.6.0
Re:Node v6.6.0 by sotojuan on Thursday September 15, 2016 @07:16PM (#12510654)
I second something like `nvm`. Even homebrew takes a long time to update their Node versions.

That said, I use `n` because for some reason `nvm` makes my shell take more than a second to startup (I've tried tons of fixes and none work).

https://github.com/tj/n

Re:Node v6.6.0 by diggan on Thursday September 15, 2016 @07:23PM (#12510693)
I have a little trick that makes nvm not impact your overall startup time.

First, put the version you commonly use in your path

  export PATH="${PATH}:/home/victor/.nvm/versions/node/v6.5.0/bin"
Then, instead of sourching nvm when your shell starts, do it when you call an alias instead.

  export NVM_DIR="/home/victor/.nvm"
  alias n=". $NVM_DIR/nvm.sh" 
Now, you have a node+npm version by default, and you can do a quick flow if you want to change

  $ n
  $ nvm install 6.6.0
  Now using node v6.5.0
Re:Node v6.6.0 by jessaustin on Friday September 16, 2016 @08:16AM (#12513469)
I thought the point of a package manager was not having to mess with stuff like that? "n" is simply better.
Re:Node v6.6.0 by diggan on Friday September 16, 2016 @04:09PM (#12516970)
Yeah, sure, but sometimes you have to go a little bit extra to have it the best...
Re:Node v6.6.0 by jbergstroem on Thursday September 15, 2016 @10:29PM (#12511489)
I do something similar to @diggan, but expand with globbing because I'm probably lazy:

  NODE_PATH=$(dirname ~/.nvm/versions/node/v6*/bin/node)
  export PATH="\
  ${NODE_PATH}:\
  ...

  export NVM_DIR="/Users/jbergstroem/.nvm"
  [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"

Also, the delay that a lot of you may be experiencing has to do with npm, not nvm.
Re:Node v6.6.0 by overcast on Thursday September 15, 2016 @08:45PM (#12511145)
'n' has always worked perfectly for me. Takes all of twenty seconds to get up to date, and switching between versions is stupid simple.
Re:Node v6.6.0 by dandanisaur on Friday September 16, 2016 @01:03AM (#12511957)
I learned this subtle trick via nvm. If you use "nvm install 6" it will automatically download the latest version.
Re:Node v6.6.0 by shriek on Friday September 16, 2016 @12:45AM (#12511892)
and

  nvm reinstall-packages v6.5.0
to reinstall all your global packages from v6.5.0 or other versions.
[dead]
Re:Node v6.6.0 by sctb on Thursday September 15, 2016 @05:45PM (#12510092)
Please stop posting deliberately inflammatory (troll) comments. We ban accounts that continue to do this.
Re:Node v6.6.0 by kristopolous on Thursday September 15, 2016 @07:59PM (#12510897)
I think you may be mistaken here. Looking at the other comments, I don't believe they're trying to be inflammatory or just trying to get a rise out of people. The user could be say, intersex, physically disabled or both.

Some people don't identify with a particular gender. I don't have any issue with my gender identity, but we just have to take the word of people who say they do.

These can be legitimately sensitive things to some people and I'm of the opinion that a sincere adult response is not to silence their voices.

Re:Node v6.6.0 by dang on Saturday September 17, 2016 @03:53PM (#12522135)
> we just have to take the word of people

Unfortunately, that's a loophole large enough to drive a troll truck through, so it isn't workable.

Moderation is guesswork. We guess wrongly sometimes, but at least it's usually easy to show us that we're wrong. In such cases we correct the mistake and say sorry.

Re:Node v6.6.0 by erlich on Friday September 16, 2016 @04:53AM (#12512708)
Curious - what did the comment say before deleted?
Re:Node v6.6.0 by molloy on Friday September 16, 2016 @05:29AM (#12512808)
If you go to your account settings and set showdead to yes it'll show up for you.