Pro Yearly is on sale from $80 to $50! »

Node.js Best Practices

Node.js Best Practices

Presentation about Node.js Best Practices presented at Nodebp.

http://risingstack.com

29955e7f5ba4bd072e7c0e98e4a788fb?s=128

Gergely Nemeth

January 21, 2015
Tweet

Transcript

  1. Node.js Best Practices Gergely Nemeth @nthgergo

  2. $ whoami Work - RisingStack Twitter - @nthgergo GitHub -

    gergelyke Stuff I write - http://blog.risingstack.com
  3. Why talking about best practices?

  4. Why talking about best practices?

  5. Why talking about best practices?

  6. Coding style

  7. Coding style - Callback convention

  8. Coding style - Callback convention - Always check for errors

    in callbacks
  9. Coding style - Callback convention - Always check for errors

    in callbacks - Return on callbacks
  10. Coding style - Callback convention - Always check for errors

    in callbacks - Return on callbacks - Try-catch in sync code only
  11. Handling errors Operational errors vs. Programmer errors

  12. Handling Operational Errors • Try to solve the error -

    if a file is missing, you may need to create one first • Retry the operation, when dealing with network communication • Tell the client, that something is not ok - used, when handling user inputs • Crash the process, when the error condition is unlikely to change on its own, like the application cannot read its configuration file
  13. Handling Programmer Errors Crash immediately. (Let supervisor/monit/forever do its job)

  14. On Workflow Start a new project with npm init

  15. On Workflow Specify a start and test script

  16. On Workflow Environment variables (NODE_ENV)

  17. On Workflow Use a style guide (https://github.com/RisingStack/node-style-guide)

  18. On Workflow Enforce the style guide (npm install --save-dev pre-commit)

  19. Configuration JS over JSON for configuration

  20. Operating Node

  21. Operating Node sudo

  22. In case you want to learn Node.js with us... Node.js

    Essentials & Best Practices training Contact us at gergely@risingstack.com
  23. iojs -p "console.log('Questions?')"