As you can notice, from our blog and other resources, Node.js community is growing extremely fast. In this post, we’d like to share with you the most interesting Node.js best practices. There are great practices, style guides, and architectural tips to your services. Please use them and improve your skills every day!
We would like to share with you the best error handling and code style practices.
- Use Async-Await or promises for async error handling. Use a reputable promise library or async-await instead which enables a much more compact and familiar code syntax like try-catch.
- Use only the built-in Error object. Use only the built-in Error object will increase uniformity and prevent loss of information.
- Distinguish operational vs programmer errors.
- Test error flows using your favorite test framework. Testing frameworks like Mocha & Chai can handle this easily.
- Use ESLint. Developers will focus on spacing and line-width.
- Node.js specific plugins. like eslint-plugin-node, eslint-plugin-mocha and eslint-plugin-node-security.
- Start a Codeblock’s Curly Braces on the Same Line. The opening curly braces of a code block should be on the same line as the opening statement.
- Use naming conventions for variables, constants, functions, and classes. This will help you to easily distinguish between plain variables/functions, and classes that require instantiation. Use descriptive names, but try to keep them short.
To see the whole list, please check here. We are sure you will like it!
And we would like to expand this topic by the description of 58 Node.js meetups that will definitely help you to find out more. Enjoy!