Ditch the var 3.8 Require modules first, not inside functions 3.9 Require modules by folders, as opposed to the files directly 3.9 Code example 3.10 Use the = operator 3.10 Code example 3.11 Use Async Await, avoid callbacks 3.12 Use arrow function expressions (=>) 4. Code Style Practices 3.1 Use ESLint 3.2 Node.js specific plugins 3.3 Start a Codeblock's Curly Braces on the Same Line Code Example 3.4 Separate your statements properly Code example 3.5 Name your functions 3.6 Use naming conventions for variables, constants, functions and classes 3.6 Code Example 3.7 Prefer const over let. Error Handling Practices 2.1 Use Async-Await or promises for async error handling 2.2 Use only the built-in Error object 2.3 Distinguish operational vs programmer errors 2.4 Handle errors centrally, not within a middleware 2.5 Document API errors using Swagger or GraphQL 2.6 Exit the process gracefully when a stranger comes to town 2.7 Use a mature logger to increase error visibility 2.8 Test error flows using your favorite test framework 2.9 Discover errors and downtime using APM products 2.10 Catch unhandled promise rejections 2.11 Fail fast, validate arguments using a dedicated library 2.12 Always await promises before returning to avoid a partial stacktrace 3. Project Structure Practices 1.1 Structure your solution by components 1.2 Layer your components, keep the web layer within its boundaries 1.3 Wrap common utilities as npm packages 1.4 Separate Express 'app' and 'server' 1.5 Use environment aware, secure and hierarchical config 2. Or just it to learn by code examples Latest Best Practices and News Welcome! 3 Things You Ought To Know First Table of Contents 1. ![]() Use it to generate a new solution skeleton with all the practices baked inside. ![]() ![]() Node.js Best Practices □ We have an official Node.js starter - Practica.js.
0 Comments
Leave a Reply. |