News for hackers. Stuff that matters.
Re:Hard-won lessons: Five years with Node.js by garysieling on Wednesday April 19, 2017 @07:38PM (#14152748)
The biggest hard lessons I've had with Node.js have been around handling errors - when I first deployed https://www.findlectures.com, I was shocked to realize that uncaught errors could take down the whole site. Not handling error callbacks is also a big problem - TypeScript has been an awesome solution though, because it can show compilation errors if you screw up function arguments.
Re:Hard-won lessons: Five years with Node.js by always_good on Wednesday April 19, 2017 @08:43PM (#14153069)
That's not Node.js. That's Express or a similar abstraction.

You can execute everything inside a promise like with Koa, which amounts to something like:

    http.createServer((req, res) => {
      handle(req)
        .then((response) => res.send(response))
        .catch(() => res.send(500))
    })
    
Where `handle` is an async function and thus all your application logic is in async/await space.
Re:Hard-won lessons: Five years with Node.js by stickfigure on Wednesday April 19, 2017 @09:58PM (#14153371)
It's Node.js - the root of the problem is also Node's strength, which is that there's effectively no stack. You can manage zillions of concurrent connections, but there's no easy way for the system to unwind bad behavior by one of those connections.

In a Java app you except all the way to the request response.

In a Go app you return all the way to the request response.

In a Node app, you have to call your way back to the request response. Or you don't, potentially leaving the whole process in an inconsistent state. The amazing concurrency of node comes at a price.

Re:Hard-won lessons: Five years with Node.js by jcheng on Wednesday April 19, 2017 @10:31PM (#14153499)
Domains were Node's answer to that, and it seemed to work pretty well. I adopted the approach for my own web framework (not JS based) and it has been an extremely useful abstraction.

They're soft-deprecated in Node now though, and AFAICT work on a replacement has stalled.

https://nodejs.org/api/domain.html

Re:Hard-won lessons: Five years with Node.js by int_19h on Thursday April 20, 2017 @01:15AM (#14154144)
And in async C# - which has the same "amazing concurrency" - it just works. Because the language will take that exception, and wrap it into a faulted task (promise) for you. So the stack may be spaghetti, but exceptions navigate it correctly same as everything else.
Re:Hard-won lessons: Five years with Node.js by turdnagel on Wednesday April 19, 2017 @08:53PM (#14153120)
But you're still error handling with `.catch()`. Without that, you'd have an uncaught Promise rejection, which could take down your Node process.
Re:Hard-won lessons: Five years with Node.js by always_good on Wednesday April 19, 2017 @08:56PM (#14153135)
It's common for people to complain about something like a syntax error taking down their whole process, so that's how I read it -- that you're trying to do "too much" catching.
Re:Hard-won lessons: Five years with Node.js by Waterluvian on Wednesday April 19, 2017 @09:06PM (#14153186)
I'm not an expert with​ deploying application servers but shouldn't part of handling lifecycle include the ability for a service to crash and be respawned?

Ie. Be okay if a syntax error crashes your server.

Re:Hard-won lessons: Five years with Node.js by phamilton on Wednesday April 19, 2017 @11:11PM (#14153620)
In a "one request per process" model, sure. But if you are handling 1000s of concurrent connections, a syntax error crashing your server means all of those connections error.
Re:Hard-won lessons: Five years with Node.js by garysieling on Wednesday April 19, 2017 @09:30PM (#14153267)
If you're comparing to J2EE, ASP.NET, Apache, etc, application servers tend to be big monoliths with lots of features, but Node is much lighter / more modular, so you end up setting that up yourself (that also surprised me)
Re:Hard-won lessons: Five years with Node.js by smokeyj on Wednesday April 19, 2017 @09:10PM (#14153199)
Yes you should be using a process manager like PM2.
Re:Hard-won lessons: Five years with Node.js by garysieling on Wednesday April 19, 2017 @09:28PM (#14153260)
Yeah, I'm happy to admit that I figured out how Node/Express work entirely by doing things wrong, and then fixing my mistakes :)

I came to this after building C#, Scala, and Java webapps, so it surprised me that this these class of coding errors could take down a site (both screwing up the try/catch or not handling promises).

There is probably some room for Node/the language/Express to make the experience better, either way it's something you'd need to know if you're new to the platform :)

Re:Hard-won lessons: Five years with Node.js by alleycat on Thursday April 20, 2017 @01:27AM (#14154192)
That's why you use a production manager like pm2
Re:Hard-won lessons: Five years with Node.js by AlexeyBrin on Thursday April 20, 2017 @07:55AM (#14155841)
pm2 will restart the app on crash if I understood correctly how if works.