These are chat archives for jescalan/roots

20th
Jun 2016
Tom Kraak
@tkraak
Jun 20 2016 19:17

I just came across this repo:

https://github.com/alanjames1987/Node.js-Best-Practices

outdated or worth exploring?

Jeff Escalante
@jescalan
Jun 20 2016 20:25
There are things in here that I disagree with
whenever anyone declares to "always" do something in a particular way, it's probably wrong
there is some good stuff in here, and it was written with good intention, but not by a javascript expert
i'll give some feedback by section here
"Always Use Asynchronous Methods": :-1: -- use async when it provides an advantage, and sync when it does. for example, if your code could be doing something else while it waits, async is better. If you are just blocking everything and waiting for the async function to return, it offers no advantage over sync other than more verbose syntax. "usually use async" is a better rule
"Never require Modules Inside of Functions": :-1: - there are times where this can be an advantage. A better rule would be "usually load all your dependencies at the top of each file"
Jeff Escalante
@jescalan
Jun 20 2016 20:31
"Save a reference to this Because it Changes Based on Context": This is javascript 101, not specific to node. Understand how context works, don't "always" save a this reference, save one if you need it. Much better usually is using an es6 arrow function. I can't remember the last time I saved a "this" reference
"Always "use strict" :-1: you can, you can not, it almost definitely will make no difference. Babel will inject this for you anyway.
"Validate that Callbacks are Callable": :-1: If you want to validate parameters, hapi/joi is a great project. We use this extensively in spike
"Callbacks Always Pass Error Parameter First": :-1: No they don't, they pass whatever the developer decided to have them pass first. Read the documentation, then you will know what parameters come in to the callback.
"Always Check for "error" in Callbacks": :+1: always check for errors in any situation where there could be an error. This is common knowledge
"Use Exception Handling When Errors Can Be Thrown": :+1: this just describes how to use a try/catch block. Again, programming 101, same deal with any language
"Use module.exports not exports": :-1: Use what is appropriate for the situation. If you don't have a default export, it's usually better to just use exports.
"Use JSDoc": :+1: yes, always
"Use a Process Manager like upstart, forever, or pm2": Use pm2. No need to consider other ones, pm2 is absolutely dominant. This is just used for production servers you are running on your own box.
"Follow CommonJS Standard": :-1: not helpful. commonjs is just node's way of handling modules, which you have no choice but to follow. As a more useful piece of advice, follow this standard: http://standardjs.com/
Jeff Escalante
@jescalan
Jun 20 2016 20:36
There ya go :sparkles:
Tom Kraak
@tkraak
Jun 20 2016 21:16
can always count on @jescalan!