Skip to content

Instantly share code, notes, and snippets.

@piranna
Last active October 10, 2019 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piranna/c5245eb657153019bf48b4990abddaee to your computer and use it in GitHub Desktop.
Save piranna/c5245eb657153019bf48b4990abddaee to your computer and use it in GitHub Desktop.
access config from a single place, propagate it using only function or constructor arguments
Single error handler
log result in a single place, or very few places, at most high level as possibleº
Don't log errors, throw them and catch them in caller function
use object destructuring from parameters
standar error responses
bunyan as logger
limit tests timeout
use allways promises instead of callbacks, or use promisify
main -> /lib/routes
/app.js
/server.js
package version
.eslintignore
"quote-props": ["error", "as-needed"],
"testEnvironment": "node"
empty functions, ignoring errbacks -> use promises
split logic from interface (express, fastify)
Don't embed test data in tests, assign it first to a variable, or if possible, use fixtures
git hooks to run tests on `pre-commit` and `pre-push`
Don't define classes as object containers, there's no types. Use directly objects
early error exit (return, throw, continue, break...)
return-else
Promises inside Promise handler
Object desctructuring and structuring
Files that export a class by default, named with the class name (including capital letter)
Don't merge promises and callbacks
if (HNres.error && HNres.error === true)
Don't return objects with an error field, throw errors or reject promises
Inversed signature of errbacks (error must be first argument)
Check actual returned value on tests, not only status
Don't use objects with error field, use correct http statuses
Git hooks to run linting and tests and generate docs before each commit and push. If tests are heavy, only linting and docs for commits is fine, but tests are mandatory before push
Standalone aceptance and unit tests (MongoBox, nock, supertest...), if you need to connect to other servers or systems, they are integration tests, run them ONLY in a CI server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment