
Debugging Node.js in Production - aaronbrethorst
http://techblog.netflix.com/2015/12/debugging-nodejs-in-production.html
======
jtchang
I am fairly new to node but find that it is hard as heck to debug. node debug
index.js seems really weird and not at all like python's pdb. Is there
something I am missing?

~~~
specialist
Trying to figure out some websocket stuff, I somehow managed to get nodejs,
autobahn, and whatnot running locally (client and server) using Jetbrains'
WebStorm on a Mac.

This tool stack makes me want to knock my teeth out.

That WebStorm's debugger (with break points!) works at all is a marvel. Props
to the JetBrains team.

------
z3t4
"Name your functions": Easier to know what the code does, flattens the
"Christmas tree from hell", no need for ugly closures, + Makes it's easier to
debug. Anonymous functions is probably the most abused syntax in JavaScript.

~~~
ameen
I've never understood JScripters' insistence on anonymous functions instead of
named ones.

As someone just delving into Node from another platform what're "proper best
practices"-based JS patterns?

~~~
nawitus
Lambdas make code really easy to read compared to making the reader skip
around the code. In addition, it reduces boilerplate code and requires less
time to be spent on naming functions. Of course, it all depends on situation.
Simple logic which is not beneficial elsewhere can be implemented as an
anonymous function in my opinion.

For example: if(objects.find(object => object.id === id)) {}

~~~
coldtea
> _Lambdas make code really easy to read compared to making the reader skip
> around the code._

You can have lambdas that are also named, e.g:

if(objects.find(function idCheck(object){ return object.id === id})

Not sure if it's possible with the new ES6 syntax [Edit: apparently it's not,
although arrow functions will automatically be assigned a name in some common
scenarios].

~~~
Killswitch
That defeats the whole purpose of fat arrow functions.

~~~
coldtea
I'm not sure what purpose you have in mind.

The main purposes of fat arrow functions is the auto-binding of this and
succinctness.

A named fat-arrow function would still retain both, and in fact the feature
was considered for ES6 back in 2013, but didn't made it. Syntax would have
been like:

if(objects.find(functionName(object) => object.id === id)) {}

------
frik
Interesting that they choose the brute force way. And that it works that good
and maybe has less overhead than instrumenting the code.

------
irishcule
Sorry if this is slightly off topic but can anyone tell me why I would not be
able to access the netflix tech blog?

Every time I try to go to it I get a "Web page unavailable" despite sites like
downforeveryoneorjustme.com telling me it is not down.

Not sure if its just my laptop as I am abroad at the moment in Italy and have
no other computer to check the site.

~~~
arca_vorago
"abroad at the moment in Italy"

Here is the basic checklist for something like this:

check your hosts file ping the website tracert the website clear dns cache
check dns server up/down temporarily disable av/firewall

If all the above indicate normal operation but it still fails, it could be
blocked anywhere upstream of you.

~~~
irishcule
It's strange, nothing in the hosts file, any ping says it can't find the host
[http://techblog.netflix.com/](http://techblog.netflix.com/), or even anyone
of those check ip sites says the same. Asked some work colleagues here and in
Ireland and it seems our company is blocking it, I guess through the firewall
which unfortunately I can't disable.

~~~
untog
I guess it is unfortunate though not too surprising that an employer would be
blocking netflix.com.

------
cdnsteve
Restify, interesting.

~~~
cvburgess
Netflix is a large supporter and active contributor (perhaps the most active?)
to Restify, so it really isn't that surprising when you think about it.

------
ryanelfman
Why not use New Relic?

~~~
jonesb6
My early impressions of New Relic were that they were a really fast and easy
way to correlate all the default logging of the web application stack. I
imagine Netflix would want something a little deeper and more customized then
this, also deploying New Relic at scale would be costly and at the very least
require an audit of potential performance implications.

------
VOYD
always bad practice to be forced to debug in production, but I guess that's
what you get in the "DevOps" model.

~~~
dap
On the contrary: there are many bugs you will not find until software is in
production. (That's not a reason not to test or roll out to staging
environments first and the like, because you can continue to find new bugs
that way. But despite all of our efforts, there remain bugs that only manifest
for the first time in production.)

~~~
VOYD
sure, but that is paramount of environments not being in sync, and inaccurate
pre-production testing.

