Skip to content

Instantly share code, notes, and snippets.

@kyleparisi
Last active August 30, 2017 13:10
Show Gist options
  • Save kyleparisi/5dc6234b6ab4c9f316bbd98948f579e2 to your computer and use it in GitHub Desktop.
Save kyleparisi/5dc6234b6ab4c9f316bbd98948f579e2 to your computer and use it in GitHub Desktop.
General Node.js notes (+lambda)

General Node.js notes (+lambda)

  • I'd recommend sticking with es6 syntax (no async-await).
  • Always consider throttling
  • Try to make scripts atomically process data that fits the lambda time allotment
  • Connections [DB] should be handled at the top most points and always wrapped in a function
  • Scripts should always exit when done doing atomic work (dangling connections problem)
  • Logging should be using a single/configurable handler (verbosity, cli, parsable)
  • Logging should be done where you see neccesary but at a minimum at the tail end + top most point of the process for feedback on the atomic data processed (then and catch should be directly visible in the entry script)
  • .then(fn) - fn should either be stupidly simple or be extractable to the point of being able to be unit tested. The name should also be painfully obvious (reference)
  • The main logic should have multiple entry scripts for things like cli, direct node invocation, and lambda calls

Bonus

Newer ES versions allow for a slew of coding styles. I'd recommend automating prettier in the commit flow so that the style can be any way you want but the outcome will follow a strict opinion.

General JS Notes

  • If your arrow function is more than 1 line, don't use syntax to make it still a 1 line body
(list, n = 3) => 
	list
	  .map(u => u.first_name)
	  .slice(0, n)
	  .join(", ") +
	  (list.length > n
		? ", and " + (list.length - n) + " more..."
		: "")

General React Notes

  • You should be explicit about what properties your elements need. Things like redux only do shallow checking. Also testing a component should be easier and more obvious with explicit props.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment