Node.js Best Practices

Node.js Best Practices

The Node.js best practices list (December 2023)
GitHub
94k
Created 6 years ago, last commit 3 months ago
232 contributors
3.91k commits
Stars added on GitHub, month by month
12
1
2
3
4
5
6
7
8
9
10
11
2022
2023
Stars added on GitHub, per day, on average
Yesterday
+20
Last week
+21.6 /day
Last month
+16.1 /day
Last 12 months
+28.0 /day
README

Node.js Best Practices

Node.js Best Practices


102 items Last update: July 19, 2023 Updated for Node 19.0.0

Follow us on Twitter! @nodepractices


Read in a different language: CNCN, FRFR, BRBR, RURU, PLPL, JAJA, EUEU (ESES, HEHE, KRKR and TRTR in progress! )


šŸŽŠ 2023 edition is here!

  • šŸ›° Modernized to 2023: Tons of text edits, new recommended libraries, and some new best practices

  • āœØ Easily focus on new content: Already visited before? Search for #new or #updated tags for new content only

  • šŸ”– Curious to see examples? We have a starter: Visit Practica.js, our application example and boilerplate (beta) to see some practices in action



Welcome! 3 Things You Ought To Know First

1. You are reading dozens of the best Node.js articles - this repository is a summary and curation of the top-ranked content on Node.js best practices, as well as content written here by collaborators

2. It is the largest compilation, and it is growing every week - currently, more than 80 best practices, style guides, and architectural tips are presented. New issues and pull requests are created every day to keep this live book updated. We'd love to see you contributing here, whether that is fixing code mistakes, helping with translations, or suggesting brilliant new ideas. See our writing guidelines here

3. Best practices have additional info - most bullets include a šŸ”—Read More link that expands on the practice with code examples, quotes from selected blogs, and more information



By Yoni Goldberg

Learn with me: As a consultant, I engage with worldwide teams on various activities like workshops and code reviews. šŸŽ‰AND... Hold on, I've just launched my beyond-the-basics testing course, which is on a šŸŽ limited-time sale until August 7th



Table of Contents

1. Project Architecture Practices (6)

ā€ƒā€ƒ1.1 Structure your solution by components #strategic #updated
ā€ƒā€ƒ1.2 Layer your components, keep the web layer within its boundaries #strategic #updated
ā€ƒā€ƒ1.3 Wrap common utilities as packages, consider publishing
ā€ƒā€ƒ1.4 Use environment aware, secure and hierarchical config #updated
ā€ƒā€ƒ1.5 Consider all the consequences when choosing the main framework #new
ā€ƒā€ƒ1.6 Use TypeScript sparingly and thoughtfully #new

2. Error Handling Practices (12)

ā€ƒā€ƒ2.1 Use Async-Await or promises for async error handling
ā€ƒā€ƒ2.2 Extend the built-in Error object #strategic #updated
ā€ƒā€ƒ2.3 Distinguish operational vs programmer errors #strategic #updated
ā€ƒā€ƒ2.4 Handle errors centrally, not within a middleware #strategic
ā€ƒā€ƒ2.5 Document API errors using OpenAPI or GraphQL
ā€ƒā€ƒ2.6 Exit the process gracefully when a stranger comes to town #strategic
ā€ƒā€ƒ2.7 Use a mature logger to increase errors visibility #updated
ā€ƒā€ƒ2.8 Test error flows using your favorite test framework #updated
ā€ƒā€ƒ2.9 Discover errors and downtime using APM products
ā€ƒā€ƒ2.10 Catch unhandled promise rejections #updated
ā€ƒā€ƒ2.11 Fail fast, validate arguments using a dedicated library
ā€ƒā€ƒ2.12 Always await promises before returning to avoid a partial stacktrace #new
ā€ƒā€ƒ2.13 Subscribe to event emitters 'error' event #new

3. Code Style Practices (12)

ā€ƒā€ƒ3.1 Use ESLint #strategic
ā€ƒā€ƒ3.2 Use Node.js eslint extension plugins #updated
ā€ƒā€ƒ3.3 Start a Codeblock's Curly Braces on the Same Line
ā€ƒā€ƒ3.4 Separate your statements properly
ā€ƒā€ƒ3.5 Name your functions
ā€ƒā€ƒ3.6 Use naming conventions for variables, constants, functions and classes
ā€ƒā€ƒ3.7 Prefer const over let. Ditch the var
ā€ƒā€ƒ3.8 Require modules first, not inside functions
ā€ƒā€ƒ3.9 Set an explicit entry point to a module/folder #updated
ā€ƒā€ƒ3.10 Use the === operator
ā€ƒā€ƒ3.11 Use Async Await, avoid callbacks #strategic
ā€ƒā€ƒ3.12 Use arrow function expressions (=>)
ā€ƒā€ƒ3.13 Avoid effects outside of functions #new

4. Testing And Overall Quality Practices (13)

ā€ƒā€ƒ4.1 At the very least, write API (component) testing #strategic
ā€ƒā€ƒ4.2 Include 3 parts in each test name #new
ā€ƒā€ƒ4.3 Structure tests by the AAA pattern #strategic
ā€ƒā€ƒ4.4 Ensure Node version is unified #new
ā€ƒā€ƒ4.5 Avoid global test fixtures and seeds, add data per-test #strategic
ā€ƒā€ƒ4.6 Tag your tests #advanced
ā€ƒā€ƒ4.7 Check your test coverage, it helps to identify wrong test patterns
ā€ƒā€ƒ4.8 Use production-like environment for e2e testing
ā€ƒā€ƒ4.9 Refactor regularly using static analysis tools
ā€ƒā€ƒ4.10 Mock responses of external HTTP services #advanced #new #advanced
ā€ƒā€ƒ4.11 Test your middlewares in isolation
ā€ƒā€ƒ4.12 Specify a port in production, randomize in testing #new
ā€ƒā€ƒ4.13 Test the five possible outcomes #strategic #new

5. Going To Production Practices (19)

ā€ƒā€ƒ5.1. Monitoring #strategic
ā€ƒā€ƒ5.2. Increase the observability using smart logging #strategic
ā€ƒā€ƒ5.3. Delegate anything possible (e.g. gzip, SSL) to a reverse proxy #strategic
ā€ƒā€ƒ5.4. Lock dependencies
ā€ƒā€ƒ5.5. Guard process uptime using the right tool
ā€ƒā€ƒ5.6. Utilize all CPU cores
ā€ƒā€ƒ5.7. Create a ā€˜maintenance endpointā€™
ā€ƒā€ƒ5.8. Discover the unknowns using APM products #advanced #updated
ā€ƒā€ƒ5.9. Make your code production-ready
ā€ƒā€ƒ5.10. Measure and guard the memory usage #advanced
ā€ƒā€ƒ5.11. Get your frontend assets out of Node
ā€ƒā€ƒ5.12. Strive to be stateless #strategic
ā€ƒā€ƒ5.13. Use tools that automatically detect vulnerabilities
ā€ƒā€ƒ5.14. Assign a transaction id to each log statement #advanced
ā€ƒā€ƒ5.15. Set NODE_ENV=production
ā€ƒā€ƒ5.16. Design automated, atomic and zero-downtime deployments #advanced
ā€ƒā€ƒ5.17. Use an LTS release of Node.js
ā€ƒā€ƒ5.18. Log to stdout, avoid specifying log destination within the app #updated
ā€ƒā€ƒ5.19. Install your packages with npm ci #new

6. Security Practices (25)

ā€ƒā€ƒ6.1. Embrace linter security rules
ā€ƒā€ƒ6.2. Limit concurrent requests using a middleware
ā€ƒā€ƒ6.3 Extract secrets from config files or use packages to encrypt them #strategic
ā€ƒā€ƒ6.4. Prevent query injection vulnerabilities with ORM/ODM libraries #strategic
ā€ƒā€ƒ6.5. Collection of generic security best practices
ā€ƒā€ƒ6.6. Adjust the HTTP response headers for enhanced security
ā€ƒā€ƒ6.7. Constantly and automatically inspect for vulnerable dependencies #strategic
ā€ƒā€ƒ6.8. Protect Users' Passwords/Secrets using bcrypt or scrypt #strategic
ā€ƒā€ƒ6.9. Escape HTML, JS and CSS output
ā€ƒā€ƒ6.10. Validate incoming JSON schemas #strategic
ā€ƒā€ƒ6.11. Support blocklisting JWTs
ā€ƒā€ƒ6.12. Prevent brute-force attacks against authorization #advanced
ā€ƒā€ƒ6.13. Run Node.js as non-root user
ā€ƒā€ƒ6.14. Limit payload size using a reverse-proxy or a middleware
ā€ƒā€ƒ6.15. Avoid JavaScript eval statements
ā€ƒā€ƒ6.16. Prevent evil RegEx from overloading your single thread execution
ā€ƒā€ƒ6.17. Avoid module loading using a variable
ā€ƒā€ƒ6.18. Run unsafe code in a sandbox
ā€ƒā€ƒ6.19. Take extra care when working with child processes #advanced
ā€ƒā€ƒ6.20. Hide error details from clients
ā€ƒā€ƒ6.21. Configure 2FA for npm or Yarn #strategic
ā€ƒā€ƒ6.22. Modify session middleware settings
ā€ƒā€ƒ6.23. Avoid DOS attacks by explicitly setting when a process should crash #advanced
ā€ƒā€ƒ6.24. Prevent unsafe redirects
ā€ƒā€ƒ6.25. Avoid publishing secrets to the npm registry
ā€ƒā€ƒ6.26. 6.26 Inspect for outdated packages
ā€ƒā€ƒ6.27. Import built-in modules using the 'node:' protocol #new

7. Performance Practices (2) (Work In Progressļø āœļø)

ā€ƒā€ƒ7.1. Don't block the event loop
ā€ƒā€ƒ7.2. Prefer native JS methods over user-land utils like Lodash

8. Docker Practices (15)

ā€ƒā€ƒ8.1 Use multi-stage builds for leaner and more secure Docker images #strategic
ā€ƒā€ƒ8.2. Bootstrap using node command, avoid npm start
ā€ƒā€ƒ8.3. Let the Docker runtime handle replication and uptime #strategic
ā€ƒā€ƒ8.4. Use .dockerignore to prevent leaking secrets
ā€ƒā€ƒ8.5. Clean-up dependencies before production
ā€ƒā€ƒ8.6. Shutdown smartly and gracefully #advanced
ā€ƒā€ƒ8.7. Set memory limits using both Docker and v8 #advanced #strategic
ā€ƒā€ƒ8.8. Plan for efficient caching
ā€ƒā€ƒ8.9. Use explicit image reference, avoid latest tag
ā€ƒā€ƒ8.10. Prefer smaller Docker base images
ā€ƒā€ƒ8.11. Clean-out build-time secrets, avoid secrets in args #strategic #new
ā€ƒā€ƒ8.12. Scan images for multi layers of vulnerabilities #advanced
ā€ƒā€ƒ8.13 Clean NODE_MODULE cache
ā€ƒā€ƒ8.14. Generic Docker practices
ā€ƒā€ƒ8.15. Lint your Dockerfile #new



1. Project Architecture Practices

āœ” 1.1 Structure your solution by business components

šŸ“ #updated

TL;DR: The root of a system should contain folders or repositories that represent reasonably sized business modules. Each component represents a product domain (i.e., bounded context), like 'user-component', 'order-component', etc. Each component has its own API, logic, and logical database. What is the significant merit? With an autonomous component, every change is performed over a granular and smaller scope - the mental overload, development friction, and deployment fear are much smaller and better. As a result, developers can move much faster. This does not necessarily demand physical separation and can be achieved using a Monorepo or with a multi-repo

my-system
ā”œā”€ apps (components)
ā”‚  ā”œā”€ orders
ā”‚  ā”œā”€ users
ā”‚  ā”œā”€ payments
ā”œā”€ libraries (generic cross-component functionality)
ā”‚  ā”œā”€ logger
ā”‚  ā”œā”€ authenticator

Otherwise: when artifacts from various modules/topics are mixed together, there are great chances of a tightly-coupled 'spaghetti' system. For example, in an architecture where 'module-a controller' might call 'module-b service', there are no clear modularity borders - every code change might affect anything else. With this approach, developers who code new features struggle to realize the scope and impact of their change. Consequently, they fear breaking other modules, and each deployment becomes slower and riskier

šŸ”— Read More: structure by components



āœ” 1.2 Layer your components with 3-tiers, keep the web layer within its boundaries

šŸ“ #updated

TL;DR: Each component should contain 'layers' - a dedicated folder for common concerns: 'entry-point' where controller lives, 'domain' where the logic lives, and 'data-access'. The primary principle of the most popular architectures is to separate the technical concerns (e.g., HTTP, DB, etc) from the pure logic of the app so a developer can code more features without worrying about infrastructural concerns. Putting each concern in a dedicated folder, also known as the 3-Tier pattern, is the simplest way to meet this goal

my-system
ā”œā”€ apps (components)
ā”‚  ā”œā”€ component-a
   ā”‚  ā”œā”€ entry-points
   ā”‚  ā”‚  ā”œā”€ api # controller comes here
   ā”‚  ā”‚  ā”œā”€ message-queue # message consumer comes here
   ā”‚  ā”œā”€ domain # features and flows: DTO, services, logic
   ā”‚  ā”œā”€ data-access # DB calls w/o ORM

Otherwise: It's often seen that developer pass web objects like request/response to functions in the domain/logic layer - this violates the separation principle and makes it harder to access later the logic code by other clients like testing code, scheduled jobs, message queues, etc

šŸ”— Read More: layer your app



āœ” 1.3 Wrap common utilities as packages, consider publishing

TL;DR: Place all reusable modules in a dedicated folder, e.g., "libraries", and underneath each module in its own folder, e.g., "/libraries/logger". Make the module an independent package with its own package.json file to increase the module encapsulation, and allows future publishing to a repository. In a Monorepo setup, modules can be consumed by 'npm linking' to their physical paths, using ts-paths or by publishing and installing from a package manager repository like the npm registry

my-system
ā”œā”€ apps (components)
  ā”‚  ā”œā”€ component-a
ā”œā”€ libraries (generic cross-component functionality)
ā”‚  ā”œā”€ logger
ā”‚  ā”‚  ā”œā”€ package.json
ā”‚  ā”‚  ā”œā”€ src
ā”‚  ā”‚  ā”‚ ā”œā”€ index.js

Otherwise: Clients of a module might import and get coupled to internal functionality of a module. With a package.json at the root, one can set a package.json.main or package.json.exports to explicitly tell which files and functions are part of the public interface

šŸ”— Read More: Structure by feature



āœ” 1.4 Use environment aware, secure and hierarchical config

šŸ“ #updated

TL;DR: A flawless configuration setup should ensure (a) keys can be read from file AND from environment variable (b) secrets are kept outside committed code (c) config is hierarchical for easier findability (d) typing support (e) validation for failing fast (f) Specify default for each key. There are a few packages that can help tick most of those boxes like convict, env-var, zod, and others

Otherwise: Consider a mandatory environment variable that wasn't provided. The app starts successfully and serve requests, some information is already persisted to DB. Then, it's realized that without this mandatory key the request can't complete, leaving the app in a dirty state

šŸ”— Read More: configuration best practices



āœ” 1.5 Consider all the consequences when choosing the main framework

šŸŒŸ #new

TL;DR: When building apps and APIs, using a framework is mandatory. It's easy to overlook alternative frameworks or important considerations and then finally land on a sub optimal option. As of 2023/2024, we believe that these four frameworks are worth considering: Nest.js, Fastify, express, and Koa. Click read more below for a detailed pros/cons of each framework. Simplistically, we believe that Nest.js is the best match for teams who wish to go OOP and/or build large-scale apps that can't get partitioned into smaller autonomous components. Fastify is our recommendation for apps with reasonably-sized components (e.g., Microservices) that are built around simple Node.js mechanics. Read our full considerations guide here

Otherwise: Due to the overwhelming amount of considerations, it's easy to make decisions based on partial information and compare apples with oranges. For example, it's believed that Fastify is a minimal web-server that should get compared with express only. In reality, it's a rich framework with many official plugins that cover many concerns

šŸ”— Read More: Choosing the right framework

āœ” 1.6 Use TypeScript sparingly and thoughtfully

šŸŒŸ #new

TL;DR: Coding without type safety is no longer an option, TypeScript is the most popular option for this mission. Use it to define variables and functions return types. With that, it is also a double edge sword that can greatly encourage complexity with its additional ~ 50 keywords and sophisticated features. Consider using it sparingly, mostly with simple types, and utilize advanced features only when a real need arises

Otherwise: Researches show that using TypeScript can help in detecting ~20% bugs earlier. Without it, also the developer experience in the IDE is intolerable. On the flip side, 80% of other bugs were not discovered using types. Consequently, typed syntax is valuable but limited. Only efficient tests can discover the whole spectrum of bugs, including type-related bugs. It might also defeat its purpose: sophisticated code features are likely to increase the code complexity, which by itself increases both the amount of bugs and the average bug fix time

šŸ”— Read More: TypeScript considerations




ā¬† Return to top

2. Error Handling Practices

āœ” 2.1 Use Async-Await or promises for async error handling

TL;DR: Handling async errors in callback style is probably the fastest way to hell (a.k.a the pyramid of doom). The best gift you can give to your code is using Promises with async-await which enables a much more compact and familiar code syntax like try-catch

Otherwise: Node.js callback style, function(err, response), is a promising way to un-maintainable code due to the mix of error handling with casual code, excessive nesting, and awkward coding patterns

šŸ”— Read More: avoiding callbacks



āœ” 2.2 Extend the built-in Error object

šŸ“ #updated

TL;DR: Some libraries throw errors as a string or as some custom type ā€“ this complicates the error handling logic and the interoperability between modules. Instead, create app error object/class that extends the built-in Error object and use it whenever rejecting, throwing or emitting an error. The app error should add useful imperative properties like the error name/code and isCatastrophic. By doing so, all errors have a unified structure and support better error handling. There is no-throw-literal ESLint rule that strictly checks that (although it has some limitations which can be solved when using TypeScript and setting the @typescript-eslint/no-throw-literal rule)

Otherwise: When invoking some component, being uncertain which type of errors come in return ā€“ it makes proper error handling much harder. Even worse, using custom types to describe errors might lead to loss of critical error information like the stack trace!

šŸ”— Read More: using the built-in error object



āœ” 2.3 Distinguish catastrophic errors from operational errors

šŸ“ #updated

TL;DR: Operational errors (e.g. API received an invalid input) refer to known cases where the error impact is fully understood and can be handled thoughtfully. On the other hand, catastrophic error (also known as programmer errors) refers to unusual code failures that dictate to gracefully restart the application

Otherwise: You may always restart the application when an error appears, but why let ~5000 online users down because of a minor, predicted, operational error? The opposite is also not ideal ā€“ keeping the application up when an unknown catastrophic issue (programmer error) occurred might lead to an unpredicted behavior. Differentiating the two allows acting tactfully and applying a balanced approach based on the given context

šŸ”— Read More: operational vs programmer error



āœ” 2.4 Handle errors centrally, not within a middleware

TL;DR: Error handling logic such as logging, deciding whether to crash and monitoring metrics should be encapsulated in a dedicated and centralized object that all entry-points (e.g. APIs, cron jobs, scheduled jobs) call when an error comes in

Otherwise: Not handling errors within a single place will lead to code duplication and probably to improperly handled errors

šŸ”— Read More: handling errors in a centralized place



āœ” 2.5 Document API errors using OpenAPI or GraphQL

TL;DR: Let your API callers know which errors might come in return so they can handle these thoughtfully without crashing. For RESTful APIs, this is usually done with documentation frameworks like OpenAPI. If you're using GraphQL, you can utilize your schema and comments as well

Otherwise: An API client might decide to crash and restart only because it received back an error it couldnā€™t understand. Note: the caller of your API might be you (very typical in a microservice environment)

šŸ”— Read More: documenting API errors in Swagger or GraphQL



āœ” 2.6 Exit the process gracefully when a stranger comes to town

TL;DR: When an unknown error occurs (catastrophic error, see best practice 2.3) - there is uncertainty about the application healthiness. In this case, there is no escape from making the error observable, shutting off connections and exiting the process. Any reputable runtime framework like Dockerized services or cloud serverless solutions will take care to restart

Otherwise: When an unfamiliar exception occurs, some object might be in a faulty state (e.g. an event emitter which is used globally and not firing events anymore due to some internal failure) and all future requests might fail or behave crazily

šŸ”— Read More: shutting the process



āœ” 2.7 Use a mature logger to increase errors visibility

šŸ“ #updated

TL;DR: A robust logging tools like Pino or Winston increases the errors visibility using features like log-levels, pretty print coloring and more. Console.log lacks these imperative features and should be avoided. The best in class logger allows attaching custom useful properties to log entries with minimized serialization performance penalty. Developers should write logs to stdout and let the infrastructure pipe the stream to the appropriate log aggregator

Otherwise: Skimming through console.logs or manually through messy text file without querying tools or a decent log viewer might keep you busy at work until late

šŸ”— Read More: using a mature logger



āœ” 2.8 Test error flows using your favorite test framework

šŸ“ #updated

TL;DR: Whether professional automated QA or plain manual developer testing ā€“ Ensure that your code not only satisfies positive scenarios but also handles and returns the right errors. On top of this, simulate deeper error flows like uncaught exceptions and ensure that the error handler treat these properly (see code examples within the "read more" section)

Otherwise: Without testing, whether automatically or manually, you canā€™t rely on your code to return the right errors. Without meaningful errors ā€“ thereā€™s no error handling

šŸ”— Read More: testing error flows



āœ” 2.9 Discover errors and downtime using APM products

TL;DR: Monitoring and performance products (a.k.a APM) proactively gauge your codebase or API so they can automagically highlight errors, crashes, and slow parts that you were missing

Otherwise: You might spend great effort on measuring API performance and downtimes, probably youā€™ll never be aware which are your slowest code parts under real-world scenario and how these affect the UX

šŸ”— Read More: using APM products



āœ” 2.10 Catch unhandled promise rejections

šŸ“ #updated

TL;DR: Any exception thrown within a promise will get swallowed and discarded unless a developer didnā€™t forget to explicitly handle it. Even if your code is subscribed to process.uncaughtException! Overcome this by registering to the event process.unhandledRejection

Otherwise: Your errors will get swallowed and leave no trace. Nothing to worry about

šŸ”— Read More: catching unhandled promise rejection



āœ” 2.11 Fail fast, validate arguments using a dedicated library

TL;DR: Assert API input to avoid nasty bugs that are much harder to track later. The validation code is usually tedious unless you are using a modern validation library like ajv, zod, or typebox

Otherwise: Consider this ā€“ your function expects a numeric argument ā€œDiscountā€ which the caller forgets to pass, later on, your code checks if Discount!=0 (amount of allowed discount is greater than zero), then it will allow the user to enjoy a discount. OMG, what a nasty bug. Can you see it?

šŸ”— Read More: failing fast



āœ” 2.12 Always await promises before returning to avoid a partial stacktrace

šŸŒŸ #new

TL;DR: Always do return await when returning a promise to benefit full error stacktrace. If a function returns a promise, that function must be declared as async function and explicitly await the promise before returning it

Otherwise: The function that returns a promise without awaiting won't appear in the stacktrace. Such missing frames would probably complicate the understanding of the flow that leads to the error, especially if the cause of the abnormal behavior is inside of the missing function

šŸ”— Read More: returning promises



āœ” 2.13 Subscribe to event emitters and streams 'error' event

šŸŒŸ #new

TL;DR: Unlike typical functions, a try-catch clause won't get errors that originate from Event Emitters and anything inherited from it (e.g., streams). Instead of try-catch, subscribe to an event emitter's 'error' event so your code can handle the error in context. When dealing with EventTargets (the web standard version of Event Emitters) there are no 'error' event and all errors end in the process.on('error) global event - in this case, at least ensure that the process crash or not based on the desired context. Also, mind that error originating from asynchronous event handlers are not get caught unless the event emitter is initialized with {captureRejections: true}

Otherwise: Event emitters are commonly used for global and key application functionality such as DB or message queue connection. When this kind of crucial objects throw an error, at best the process will crash due to unhandled exception. Even worst, it will stay alive as a zombie while a key functionality is turned off




ā¬† Return to top

3. Code Patterns And Style Practices

āœ” 3.1 Use ESLint

TL;DR: ESLint is the de-facto standard for checking possible code errors and fixing code style, not only to identify nitty-gritty spacing issues but also to detect serious code anti-patterns like developers throwing errors without classification. Though ESLint can automatically fix code styles, other tools like prettier are more powerful in formatting the fix and work in conjunction with ESLint

Otherwise: Developers will focus on tedious spacing and line-width concerns and time might be wasted overthinking the project's code style

šŸ”— Read More: Using ESLint and Prettier



āœ” 3.2 Use Node.js eslint extension plugins

šŸ“ #updated

TL;DR: On top of ESLint standard rules that cover vanilla JavaScript, add Node.js specific plugins like eslint-plugin-node, eslint-plugin-mocha and eslint-plugin-node-security, eslint-plugin-require, /eslint-plugin-jest and other useful rules

Otherwise: Many faulty Node.js code patterns might escape under the radar. For example, developers might require(variableAsPath) files with a variable given as a path which allows attackers to execute any JS script. Node.js linters can detect such patterns and complain early



āœ” 3.3 Start a Codeblock's Curly Braces on the Same Line

TL;DR: The opening curly braces of a code block should be on the same line as the opening statement

Code Example

// Do
function someFunction() {
  // code block
}

// Avoid
function someFunction()
{
  // code block
}

Otherwise: Deferring from this best practice might lead to unexpected results, as seen in the StackOverflow thread below:

šŸ”— Read more: "Why do results vary based on curly brace placement?" (StackOverflow)



āœ” 3.4 Separate your statements properly

No matter if you use semicolons or not to separate your statements, knowing the common pitfalls of improper linebreaks or automatic semicolon insertion, will help you to eliminate regular syntax errors.

TL;DR: Use ESLint to gain awareness about separation concerns. Prettier or Standardjs can automatically resolve these issues.

Otherwise: As seen in the previous section, JavaScript's interpreter automatically adds a semicolon at the end of a statement if there isn't one, or considers a statement as not ended where it should, which might lead to some undesired results. You can use assignments and avoid using immediately invoked function expressions to prevent most of the unexpected errors.

Code example

// Do
function doThing() {
    // ...
}

doThing()

// Do

const items = [1, 2, 3]
items.forEach(console.log)

// Avoid ā€” throws exception
const m = new Map()
const a = [1,2,3]
[...m.values()].forEach(console.log)
> [...m.values()].forEach(console.log)
>  ^^^
> SyntaxError: Unexpected token ...

// Avoid ā€” throws exception
const count = 2 // it tries to run 2(), but 2 is not a function
(function doSomething() {
  // do something amazing
}())
// put a semicolon before the immediate invoked function, after the const definition, save the return value of the anonymous function to a variable or avoid IIFEs altogether

šŸ”— Read more: "Semi ESLint rule" šŸ”— Read more: "No unexpected multiline ESLint rule"



āœ” 3.5 Name your functions

TL;DR: Name all functions, including closures and callbacks. Avoid anonymous functions. This is especially useful when profiling a node app. Naming all functions will allow you to easily understand what you're looking at when checking a memory snapshot

Otherwise: Debugging production issues using a core dump (memory snapshot) might become challenging as you notice significant memory consumption from anonymous functions



āœ” 3.6 Use naming conventions for variables, constants, functions and classes

TL;DR: Use lowerCamelCase when naming constants, variables and functions, UpperCamelCase (capital first letter as well) when naming classes and UPPER_SNAKE_CASE when naming global or static variables. This will help you to easily distinguish between plain variables, functions, classes that require instantiation and variables declared at global module scope. Use descriptive names, but try to keep them short

Otherwise: JavaScript is the only language in the world that allows invoking a constructor ("Class") directly without instantiating it first. Consequently, Classes and function-constructors are differentiated by starting with UpperCamelCase

3.6 Code Example

// for global variables names we use the const/let keyword and UPPER_SNAKE_CASE
let MUTABLE_GLOBAL = "mutable value";
const GLOBAL_CONSTANT = "immutable value";
const CONFIG = {
  key: "value",
};

// examples of UPPER_SNAKE_CASE convention in nodejs/javascript ecosystem
// in javascript Math.PI module
const PI = 3.141592653589793;

// https://github.com/nodejs/node/blob/b9f36062d7b5c5039498e98d2f2c180dca2a7065/lib/internal/http2/core.js#L303
// in nodejs http2 module
const HTTP_STATUS_OK = 200;
const HTTP_STATUS_CREATED = 201;

// for class name we use UpperCamelCase
class SomeClassExample {
  // for static class properties we use UPPER_SNAKE_CASE
  static STATIC_PROPERTY = "value";
}

// for functions names we use lowerCamelCase
function doSomething() {
  // for scoped variable names we use the const/let keyword and lowerCamelCase
  const someConstExample = "immutable value";
  let someMutableExample = "mutable value";
}



āœ” 3.7 Prefer const over let. Ditch the var

TL;DR: Using const means that once a variable is assigned, it cannot be reassigned. Preferring const will help you to not be tempted to use the same variable for different uses, and make your code clearer. If a variable needs to be reassigned, in a for loop, for example, use let to declare it. Another important aspect of let is that a variable declared using it is only available in the block scope in which it was defined. var is function scoped, not block-scoped, and shouldn't be used in ES6 now that you have const and let at your disposal

Otherwise: Debugging becomes way more cumbersome when following a variable that frequently changes

šŸ”— Read more: JavaScript ES6+: var, let, or const?



āœ” 3.8 Require modules first, not inside functions

TL;DR: Require modules at the beginning of each file, before and outside of any functions. This simple best practice will not only help you easily and quickly tell the dependencies of a file right at the top but also avoids a couple of potential problems

Otherwise: Requires are run synchronously by Node.js. If they are called from within a function, it may block other requests from being handled at a more critical time. Also, if a required module or any of its dependencies throw an error and crash the server, it is best to find out about it as soon as possible, which might not be the case if that module is required from within a function



āœ” 3.9 Set an explicit entry point to a module/folder

šŸ“ #updated

TL;DR: When developing a module/library, set an explicit root file that exports the public and interesting code. Discourage the client code from importing deep files and becoming familiar with the internal structure. With commonjs (require), this can be done with an index.js file at the folder's root or the package.json.main field. With ESM (import), if a package.json exists on the root, the field "exports" allow specifying the module's root file. If no package.json exists, you may put an index.js file on the root which re-exports all the public functionality

Otherwise: Having an explicit root file acts like a public 'interface' that encapsulates the internal, directs the caller to the public code and facilitates future changes without breaking the contract

3.9 Code example - avoid coupling the client to the module structure

// Avoid: client has deep familiarity with the internals

// Client code
const SMSWithMedia = require("./SMSProvider/providers/media/media-provider.js");

// Better: explicitly export the public functions

//index.js, module code
module.exports.SMSWithMedia = require("./SMSProvider/providers/media/media-provider.js");

// Client code
const { SMSWithMedia } = require("./SMSProvider");



āœ” 3.10 Use the === operator

TL;DR: Prefer the strict equality operator === over the weaker abstract equality operator ==. == will compare two variables after converting them to a common type. There is no type conversion in ===, and both variables must be of the same type to be equal

Otherwise: Unequal variables might return true when compared with the == operator

3.10 Code example

"" == "0"; // false
0 == ""; // true
0 == "0"; // true

false == "false"; // false
false == "0"; // true

false == undefined; // false
false == null; // false
null == undefined; // true

" \t\r\n " == 0; // true

All statements above will return false if used with ===



āœ” 3.11 Use Async Await, avoid callbacks

TL;DR: Async-await is the simplest way to express an asynchronous flow as it makes asynchronous code look synchronous. Async-await will also result in much more compact code and support for try-catch. This technique now supersedes callbacks and promises in most cases. Using it in your code is probably the best gift one can give to the code reader

Otherwise: Handling async errors in callback style are probably the fastest way to hell - this style forces to check errors all over, deal with awkward code nesting, and makes it difficult to reason about the code flow

šŸ”—Read more: Guide to async-await 1.0



āœ” 3.12 Use arrow function expressions (=>)

TL;DR: Though it's recommended to use async-await and avoid function parameters when dealing with older APIs that accept promises or callbacks - arrow functions make the code structure more compact and keep the lexical context of the root function (i.e. this)

Otherwise: Longer code (in ES5 functions) is more prone to bugs and cumbersome to read

šŸ”— Read more: Itā€™s Time to Embrace Arrow Functions



āœ” 3.13 Avoid effects outside of functions

šŸŒŸ #new

TL;DR: Avoid putting code with effects like network or DB calls outside of functions. Such a code will be executed immediately when another file requires the file. This 'floating' code might get executed when the underlying system is not ready yet. It also comes with a performance penalty even when this module's functions will finally not be used in runtime. Last, mocking these DB/network calls for testing is harder outside of functions. Instead, put this code inside functions that should get called explicitly. If some DB/network code must get executed right when the module loads, consider using the factory or revealing module patterns

Otherwise: A typical web framework sets error handler, environment variables and monitoring. When DB/network calls are made before the web framework is initialized, they won't be monitored or fail due to a lack of configuration data




ā¬† Return to top

4. Testing And Overall Quality Practices

_We have dedicated guides for testing, see below. The best practices list here is a brief summary of these guides

a. JavaScript testing best practices b. Node.js testing - beyond the basics _

āœ” 4.1 At the very least, write API (component) testing

TL;DR: Most projects just don't have any automated testing due to short timetables or often the 'testing project' ran out of control and was abandoned. For that reason, prioritize and start with API testing which is the easiest way to write and provides more coverage than unit testing (you may even craft API tests without code using tools like Postman). Afterwards, should you have more resources and time, continue with advanced test types like unit testing, DB testing, performance testing, etc

Otherwise: You may spend long days on writing unit tests to find out that you got only 20% system coverage



āœ” 4.2 Include 3 parts in each test name

šŸŒŸ #new

TL;DR: Make the test speak at the requirements level so it's self-explanatory also to QA engineers and developers who are not familiar with the code internals. State in the test name what is being tested (unit under test), under what circumstances, and what is the expected result

Otherwise: A deployment just failed, a test named ā€œAdd productā€ failed. Does this tell you what exactly is malfunctioning?

šŸ”— Read More: Include 3 parts in each test name



āœ” 4.3 Structure tests by the AAA pattern

šŸŒŸ #new

TL;DR: Structure your tests with 3 well-separated sections: Arrange, Act & Assert (AAA). The first part includes the test setup, then the execution of the unit under test, and finally the assertion phase. Following this structure guarantees that the reader spends no brain CPU on understanding the test plan

Otherwise: Not only you spend long daily hours on understanding the main code, but now also what should have been the simple part of the day (testing) stretches your brain

šŸ”— Read More: Structure tests by the AAA pattern



āœ” 4.4 Ensure Node version is unified

šŸŒŸ #new

TL;DR: Use tools that encourage or enforce the same Node.js version across different environments and developers. Tools like nvm, and Volta allow specifying the project's version in a file so each team member can run a single command to conform with the project's version. Optionally, this definition can be replicated to CI and the production runtime (e.g., copy the specified value to .Dockerfile build and to the CI declaration file)

Otherwise: A developer might face or miss an error because she uses a different Node.js version than her teammates. Even worse - the production runtime might be different than the environment where tests were executed



āœ” 4.5 Avoid global test fixtures and seeds, add data per-test

TL;DR: To prevent test coupling and easily reason about the test flow, each test should add and act on its own set of DB rows. Whenever a test needs to pull or assume the existence of some DB data - it must explicitly add that data and avoid mutating any other records

Otherwise: Consider a scenario where deployment is aborted due to failing tests, team is now going to spend precious investigation time that ends in a sad conclusion: the system works well, the tests however interfere with each other and break the build

šŸ”— Read More: Avoid global test fixtures



āœ” 4.6 Tag your tests

TL;DR: Different tests must run on different scenarios: quick smoke, IO-less, tests should run when a developer saves or commits a file, full end-to-end tests usually run when a new pull request is submitted, etc. This can be achieved by tagging tests with keywords like #cold #api #sanity so you can grep with your testing harness and invoke the desired subset. For example, this is how you would invoke only the sanity test group with Mocha: mocha --grep 'sanity'

Otherwise: Running all the tests, including tests that perform dozens of DB queries, any time a developer makes a small change can be extremely slow and keeps developers away from running tests



āœ” 4.7 Check your test coverage, it helps to identify wrong test patterns

TL;DR: Code coverage tools like Istanbul/NYC are great for 3 reasons: it comes for free (no effort is required to benefit this reports), it helps to identify a decrease in testing coverage, and last but not least it highlights testing mismatches: by looking at colored code coverage reports you may notice, for example, code areas that are never tested like catch clauses (meaning that tests only invoke the happy paths and not how the app behaves on errors). Set it to fail builds if the coverage falls under a certain threshold

Otherwise: There won't be any automated metric telling you when a large portion of your code is not covered by testing



āœ” 4.8 Use production-like environment for e2e testing

TL;DR: End to end (e2e) testing which includes live data used to be the weakest link of the CI process as it depends on multiple heavy services like DB. Use an environment which is as close to your real production environment as possible like a-continue (Missed -continue here, needs content. Judging by the Otherwise clause, this should mention docker-compose)

Otherwise: Without docker-compose, teams must maintain a testing DB for each testing environment including developers' machines, keep all those DBs in sync so test results won't vary across environments



āœ” 4.9 Refactor regularly using static analysis tools

TL;DR: Using static analysis tools helps by giving objective ways to improve code quality and keeps your code maintainable. You can add static analysis tools to your CI build to fail when it finds code smells. Its main selling points over plain linting are the ability to inspect quality in the context of multiple files (e.g. detect duplications), perform advanced analysis (e.g. code complexity), and follow the history and progress of code issues. Two examples of tools you can use are Sonarqube (2,600+ stars) and Code Climate (1,500+ stars).

Otherwise: With poor code quality, bugs and performance will always be an issue that no shiny new library or state of the art features can fix

šŸ”— Read More: Refactoring!



āœ” 4.10 Mock responses of external HTTP services

šŸŒŸ #new

TL;DR: Use network mocking tools to simulate responses of external collaborators' services that are approached over the network (e.g., REST, Graph). This is imperative not only to isolate the component under test but mostly to simulate non-happy path flows. Tools like nock (in-process) or Mock-Server allow defining a specific response of external service in a single line of code. Remember to simulate also errors, delays, timeouts, and any other event that is likely to happen in production

Otherwise: Allowing your component to reach real external services instances will likely result in naive tests that mostly cover happy paths. The tests might also be flaky and slow

šŸ”— Read More: Mock external services

āœ” 4.11 Test your middlewares in isolation

TL;DR: When a middleware holds some immense logic that spans many requests, it is worth testing it in isolation without waking up the entire web framework. This can be easily achieved by stubbing and spying on the {req, res, next} objects

Otherwise: A bug in Express middleware === a bug in all or most requests

šŸ”— Read More: Test middlewares in isolation

āœ” 4.12 Specify a port in production, randomize in testing

šŸŒŸ #new

TL;DR: When testing against the API, it's common and desirable to initialize the web server inside the tests. Let the server randomize the web server port in testing to prevent collisions. If you're using Node.js http server (used by most frameworks), doing so demands nothing but passing a port number zero - this will randomize an available port

Otherwise: Specifying a fixed port will prevent two testing processes from running at the same time. Most of the modern test runners run with multiple processes by default

šŸ”— Read More: Randomize a port for testing

āœ” 4.13 Test the five possible outcomes

šŸŒŸ #new

TL;DR: When testing a flow, ensure to cover five potential categories. Any time some action is triggered (e.g., API call), a reaction occurs, a meaningful outcome is produced and calls for testing. There are five possible outcome types for every flow: a response, a visible state change (e.g., DB), an outgoing API call, a new message in a queue, and an observability call (e.g., logging, metric). See a checklist here. Each type of outcome comes with unique challenges and techniques to mitigate those challenges - we have a dedicated guide about this topic: Node.js testing - beyond the basics

Otherwise: Consider a case when testing the addition of a new product to the system. It's common to see tests that assert on a valid response only. What if the product was failed to persist regardless of the positive response? what if when adding a new product demands calling some external service, or putting a message in the queue - shouldn't the test assert these outcomes as well? It's easy to overlook various paths, this is where a checklist comes handy

šŸ”— Read More: Test five outcomes




ā¬† Return to top

5. Going To Production Practices

āœ” 5.1. Monitoring

TL;DR: Monitoring is a game of finding out issues before customers do ā€“ obviously this should be assigned unprecedented importance. The market is overwhelmed with offers thus consider starting with defining the basic metrics you must follow (my suggestions inside), then go over additional fancy features and choose the solution that ticks all boxes. In any case, the 4 layers of observability must be covered: uptime, metrics with focus on user-facing symptoms and Node.js technical metrics like event loop lag, distributed flows measurement with Open Telemetry and logging. Click ā€˜Read Moreā€™ below for an overview of the solutions

Otherwise: Failure === disappointed customers. Simple

šŸ”— Read More: Monitoring!



āœ” 5.2. Increase the observability using smart logging

TL;DR: Logs can be a dumb warehouse of debug statements or the enabler of a beautiful dashboard that tells the story of your app. Plan your logging platform from day 1: how logs are collected, stored and analyzed to ensure that the desired information (e.g. error rate, following an entire transaction through services and servers, etc) can really be extracted

Otherwise: You end up with a black box that is hard to reason about, then you start re-writing all logging statements to add additional information

šŸ”— Read More: Increase transparency using smart logging



āœ” 5.3. Delegate anything possible (e.g. gzip, SSL) to a reverse proxy

TL;DR: Node is quite bad at doing CPU intensive tasks like gzipping, SSL termination, etc. You should use specialized infrastructure like nginx, HAproxy or cloud vendor services instead

Otherwise: Your poor single thread will stay busy doing infrastructural tasks instead of dealing with your application core and performance will degrade accordingly

šŸ”— Read More: Delegate anything possible (e.g. gzip, SSL) to a reverse proxy



āœ” 5.4. Lock dependencies

TL;DR: Your code must be identical across all environments, but without a special lockfile npm lets dependencies drift across environments. Ensure to commit your package-lock.json so all the environments will be identical

Otherwise: QA will thoroughly test the code and approve a version that will behave differently in production. Even worse, different servers in the same production cluster might run different code

šŸ”— Read More: Lock dependencies



āœ” 5.5. Guard process uptime using the right tool

TL;DR: The process must go on and get restarted upon failures. Modern runtime platforms like Docker-ized platforms (e.g. Kubernetes), and Serverless take care for this automatically. When the app is hosted on a bare metal server, one must take care for a process management tools like systemd. Avoid including a custom process management tool in a modern platform that monitors an app instance (e.g., Kubernetes) - doing so will hide failures from the infrastructure. When the underlying infrastructure is not aware of errors, it can't perform useful mitigation steps like re-placing the instance in a different location

Otherwise: Running dozens of instances without a clear strategy and too many tools together (cluster management, docker, PM2) might lead to DevOps chaos

šŸ”— Read More: Guard process uptime using the right tool



āœ” 5.6. Utilize all CPU cores

TL;DR: At its basic form, a Node app runs on a single CPU core while all others are left idling. Itā€™s your duty to replicate the Node process and utilize all CPUs. Most of the modern run-times platform (e.g., Kubernetes) allow replicating instances of the app but they won't verify that all cores are utilized - this is your duty. If the app is hosted on a bare server, it's also your duty to use some process replication solution (e.g. systemd)

Otherwise: Your app will likely utilize only 25% of its available resources(!) or even less. Note that a typical server has 4 CPU cores or more, naive deployment of Node.js utilizes only 1 (even using PaaS services like AWS beanstalk!)

šŸ”— Read More: Utilize all CPU cores



āœ” 5.7. Create a ā€˜maintenance endpointā€™

TL;DR: Expose a set of system-related information, like memory usage and REPL, etc in a secured API. Although itā€™s highly recommended to rely on standard and battle-tested tools, some valuable information and operations are easier done using code

Otherwise: Youā€™ll find that youā€™re performing many ā€œdiagnostic deploysā€ ā€“ shipping code to production only to extract some information for diagnostic purposes

šŸ”— Read More: Create a ā€˜maintenance endpointā€™



āœ” 5.8. Discover the unknowns using APM products

šŸ“ #updated

TL;DR: Consider adding another safety layer to the production stack - APM. While the majority of symptoms and causes can be detected using traditional monitoring techniques, in a distributed system there is more than meets the eye. Application monitoring and performance products (a.k.a. APM) can auto-magically go beyond traditional monitoring and provide additional layer of discovery and developer-experience. For example, some APM products can highlight a transaction that loads too slow on the end-user's side while suggesting the root cause. APMs also provide more context for developers who try to troubleshoot a log error by showing what was the server busy with when the error occurred. To name a few example

Otherwise: You might spend great effort on measuring API performance and downtimes, probably youā€™ll never be aware which is your slowest code parts under real-world scenario and how these affect the UX

šŸ”— Read More: Discover errors and downtime using APM products



āœ” 5.9. Make your code production-ready

TL;DR: Code with the end in mind, plan for production from day 1. This sounds a bit vague so Iā€™ve compiled a few development tips that are closely related to production maintenance (click 'Read More')

Otherwise: A world champion IT/DevOps guy wonā€™t save a system that is badly written

šŸ”— Read More: Make your code production-ready



āœ” 5.10. Measure and guard the memory usage

TL;DR: Node.js has controversial relationships with memory: the v8 engine has soft limits on memory usage (1.4GB) and there are known paths to leak memory in Nodeā€™s code ā€“ thus watching Nodeā€™s process memory is a must. In small apps, you may gauge memory periodically using shell commands but in medium-large apps consider baking your memory watch into a robust monitoring system

Otherwise: Your process memory might leak a hundred megabytes a day like how it happened at Walmart

šŸ”— Read More: Measure and guard the memory usage



āœ” 5.11. Get your frontend assets out of Node

TL;DR: Serve frontend content using a specialized infrastructure (nginx, S3, CDN) because Node performance gets hurt when dealing with many static files due to its single-threaded model. One exception to this guideline is when doing server-side rendering

Otherwise: Your single Node thread will be busy streaming hundreds of html/images/angular/react files instead of allocating all its resources for the task it was born for ā€“ serving dynamic content

šŸ”— Read More: Get your frontend assets out of Node



āœ” 5.12. Strive to be stateless

TL;DR: Store any type of data (e.g. user sessions, cache, uploaded files) within external data stores. When the app holds data in-process this adds additional layer of maintenance complexity like routing users to the same instance and higher cost of restarting a process. To enforce and encourage a stateless approach, most modern runtime platforms allows 'reapp-ing' instances periodically

Otherwise: Failure at a given server will result in application downtime instead of just killing a faulty machine. Moreover, scaling-out elasticity will get more challenging due to the reliance on a specific server

šŸ”— Read More: Be stateless, kill your Servers almost every day



āœ” 5.13. Use tools that automatically detect vulnerabilities

TL;DR: Even the most reputable dependencies such as Express have known vulnerabilities (from time to time) that can put a system at risk. This can be easily tamed using community and commercial tools that constantly check for vulnerabilities and warn (locally or at GitHub), some can even patch them immediately

Otherwise: Keeping your code clean from vulnerabilities without dedicated tools will require you to constantly follow online publications about new threats. Quite tedious

šŸ”— Read More: Use tools that automatically detect vulnerabilities



āœ” 5.14. Assign a transaction id to each log statement

TL;DR: Assign the same identifier, transaction-id: uuid(), to each log entry within a single request (also known as correlation-id/tracing-id/request-context). Then when inspecting errors in logs, easily conclude what happened before and after. Node has a built-in mechanism, AsyncLocalStorage, for keeping the same context across asynchronous calls. see code examples inside

Otherwise: Looking at a production error log without the context ā€“ what happened before ā€“ makes it much harder and slower to reason about the issue

šŸ”— Read More: Assign ā€˜TransactionIdā€™ to each log statement



āœ” 5.15. Set NODE_ENV=production

TL;DR: Set the environment variable NODE_ENV to ā€˜productionā€™ or ā€˜developmentā€™ to flag whether production optimizations should get activated ā€“ some npm packages determine the current environment and optimize their code for production

Otherwise: Omitting this simple property might greatly degrade performance when dealing with some specific libraries like Express server-side rendering

šŸ”— Read More: Set NODE_ENV=production



āœ” 5.16. Design automated, atomic and zero-downtime deployments

TL;DR: Research shows that teams who perform many deployments lower the probability of severe production issues. Fast and automated deployments that donā€™t require risky manual steps and service downtime significantly improve the deployment process. You should probably achieve this using Docker combined with CI tools as they became the industry standard for streamlined deployment

Otherwise: Long deployments -> production downtime & human-related error -> team unconfident in making deployment -> fewer deployments and features



āœ” 5.17. Use an LTS release of Node.js

TL;DR: Ensure you are using an LTS version of Node.js to receive critical bug fixes, security updates and performance improvements

Otherwise: Newly discovered bugs or vulnerabilities could be used to exploit an application running in production, and your application may become unsupported by various modules and harder to maintain

šŸ”— Read More: Use an LTS release of Node.js



āœ” 5.18. Log to stdout, avoid specifying log destination within the app

šŸ“ #updated

TL;DR: Log destinations should not be hard-coded by developers within the application code, but instead should be defined by the execution environment the application runs in. Developers should write logs to stdout using a logger utility and then let the execution environment (container, server, etc.) pipe the stdout stream to the appropriate destination (i.e. Splunk, Graylog, ElasticSearch, etc.).

Otherwise: If developers set the log routing, less flexibility is left for the ops professional who wishes to customize it. Beyond this, if the app tries to log directly to a remote location (e.g., Elastic Search), in case of panic or crash - further logs that might explain the problem won't arrive

šŸ”— Read More: Log Routing



āœ” 5.19. Install your packages with npm ci

TL;DR: Run npm ci to strictly do a clean install of your dependencies matching package.json and package-lock.json. Obviously production code must use the exact version of the packages that were used for testing. While package-lock.json file sets strict version for dependencies, in case of mismatch with the file package.json, the command 'npm install' will treat package.json as the source of truth. On the other hand, the command 'npm ci' will exit with error in case of mismatch between these files

Otherwise: QA will thoroughly test the code and approve a version that will behave differently in production. Even worse, different servers in the same production cluster might run different code.

šŸ”— Read More: Use npm ci




ā¬† Return to top

6. Security Best Practices

54 items

āœ” 6.1. Embrace linter security rules

TL;DR: Make use of security-related linter plugins such as eslint-plugin-security to catch security vulnerabilities and issues as early as possible, preferably while they're being coded. This can help catching security weaknesses like using eval, invoking a child process or importing a module with a string literal (e.g. user input). Click 'Read more' below to see code examples that will get caught by a security linter

Otherwise: What could have been a straightforward security weakness during development becomes a major issue in production. Also, the project may not follow consistent code security practices, leading to vulnerabilities being introduced, or sensitive secrets committed into remote repositories

šŸ”— Read More: Lint rules



āœ” 6.2. Limit concurrent requests using a middleware

TL;DR: DOS attacks are very popular and relatively easy to conduct. Implement rate limiting using an external service such as cloud load balancers, cloud firewalls, nginx, rate-limiter-flexible package, or (for smaller and less critical apps) a rate-limiting middleware (e.g. express-rate-limit)

Otherwise: An application could be subject to an attack resulting in a denial of service where real users receive a degraded or unavailable service.

šŸ”— Read More: Implement rate limiting



āœ” 6.3 Extract secrets from config files or use packages to encrypt them

TL;DR: Never store plain-text secrets in configuration files or source code. Instead, make use of secret-management systems like Vault products, Kubernetes/Docker Secrets, or using environment variables. As a last resort, secrets stored in source control must be encrypted and managed (rolling keys, expiring, auditing, etc). Make use of pre-commit/push hooks to prevent committing secrets accidentally

Otherwise: Source control, even for private repositories, can mistakenly be made public, at which point all secrets are exposed. Access to source control for an external party will inadvertently provide access to related systems (databases, apis, services, etc).

šŸ”— Read More: Secret management



āœ” 6.4. Prevent query injection vulnerabilities with ORM/ODM libraries

TL;DR: To prevent SQL/NoSQL injection and other malicious attacks, always make use of an ORM/ODM or a database library that escapes data or supports named or indexed parameterized queries, and takes care of validating user input for expected types. Never just use JavaScript template strings or string concatenation to inject values into queries as this opens your application to a wide spectrum of vulnerabilities. All the reputable Node.js data access libraries (e.g. Sequelize, Knex, mongoose) have built-in protection against injection attacks.

Otherwise: Unvalidated or unsanitized user input could lead to operator injection when working with MongoDB for NoSQL, and not using a proper sanitization system or ORM will easily allow SQL injection attacks, creating a giant vulnerability.

šŸ”— Read More: Query injection prevention using ORM/ODM libraries



āœ” 6.5. Collection of generic security best practices

TL;DR: This is a collection of security advice that is not related directly to Node.js - the Node implementation is not much different than any other language. Click read more to skim through.

šŸ”— Read More: Common security best practices



āœ” 6.6. Adjust the HTTP response headers for enhanced security

TL;DR: Your application should be using secure headers to prevent attackers from using common attacks like cross-site scripting (XSS), clickjacking and other malicious attacks. These can be configured easily using modules like helmet.

Otherwise: Attackers could perform direct attacks on your application's users, leading to huge security vulnerabilities

šŸ”— Read More: Using secure headers in your application



āœ” 6.7. Constantly and automatically inspect for vulnerable dependencies

TL;DR: With the npm ecosystem it is common to have many dependencies for a project. Dependencies should always be kept in check as new vulnerabilities are found. Use tools like npm audit or snyk to track, monitor and patch vulnerable dependencies. Integrate these tools with your CI setup so you catch a vulnerable dependency before it makes it to production.

Otherwise: An attacker could detect your web framework and attack all its known vulnerabilities.

šŸ”— Read More: Dependency security



āœ” 6.8. Protect Users' Passwords/Secrets using bcrypt or scrypt

TL;DR: Passwords or secrets (e.g. API keys) should be stored using a secure hash + salt function like bcrypt,scrypt, or worst case pbkdf2.

Otherwise: Passwords and secrets that are stored without using a secure function are vulnerable to brute forcing and dictionary attacks that will lead to their disclosure eventually.

šŸ”— Read More: User Passwords



āœ” 6.9. Escape HTML, JS and CSS output

TL;DR: Untrusted data that is sent down to the browser might get executed instead of just being displayed, this is commonly referred as a cross-site-scripting (XSS) attack. Mitigate this by using dedicated libraries that explicitly mark the data as pure content that should never get executed (i.e. encoding, escaping)

Otherwise: An attacker might store malicious JavaScript code in your DB which will then be sent as-is to the poor clients

šŸ”— Read More: Escape output



āœ” 6.10. Validate incoming JSON schemas

TL;DR: Validate the incoming requests' body payload and ensure it meets expectations, fail fast if it doesn't. To avoid tedious validation coding within each route you may use lightweight JSON-based validation schemas such as jsonschema or joi

Otherwise: Your generosity and permissive approach greatly increases the attack surface and encourages the attacker to try out many inputs until they find some combination to crash the application

šŸ”— Read More: Validate incoming JSON schemas



āœ” 6.11. Support blocklisting JWTs

TL;DR: When using JSON Web Tokens (for example, with Passport.js), by default there's no mechanism to revoke access from issued tokens. Once you discover some malicious user activity, there's no way to stop them from accessing the system as long as they hold a valid token. Mitigate this by implementing a blocklist of untrusted tokens that are validated on each request.

Otherwise: Expired, or misplaced tokens could be used maliciously by a third party to access an application and impersonate the owner of the token.

šŸ”— Read More: Blocklist JSON Web Tokens



āœ” 6.12. Prevent brute-force attacks against authorization

TL;DR: A simple and powerful technique is to limit authorization attempts using two metrics:

  1. The first is number of consecutive failed attempts by the same user unique ID/name and IP address.
  2. The second is number of failed attempts from an IP address over some long period of time. For example, block an IP address if it makes 100 failed attempts in one day.

Otherwise: An attacker can issue unlimited automated password attempts to gain access to privileged accounts on an application

šŸ”— Read More: Login rate limiting



āœ” 6.13. Run Node.js as non-root user

TL;DR: There is a common scenario where Node.js runs as a root user with unlimited permissions. For example, this is the default behaviour in Docker containers. It's recommended to create a non-root user and either bake it into the Docker image (examples given below) or run the process on this user's behalf by invoking the container with the flag "-u username"

Otherwise: An attacker who manages to run a script on the server gets unlimited power over the local machine (e.g. change iptable and re-route traffic to their server)

šŸ”— Read More: Run Node.js as non-root user



āœ” 6.14. Limit payload size using a reverse-proxy or a middleware

TL;DR: The bigger the body payload is, the harder your single thread works in processing it. This is an opportunity for attackers to bring servers to their knees without tremendous amount of requests (DOS/DDOS attacks). Mitigate this limiting the body size of incoming requests on the edge (e.g. firewall, ELB) or by configuring express body parser to accept only small-size payloads

Otherwise: Your application will have to deal with large requests, unable to process the other important work it has to accomplish, leading to performance implications and vulnerability towards DOS attacks

šŸ”— Read More: Limit payload size



āœ” 6.15. Avoid JavaScript eval statements

TL;DR: eval is evil as it allows executing custom JavaScript code during run time. This is not just a performance concern but also an important security concern due to malicious JavaScript code that may be sourced from user input. Another language feature that should be avoided is new Function constructor. setTimeout and setInterval should never be passed dynamic JavaScript code either.

Otherwise: Malicious JavaScript code finds a way into text passed into eval or other real-time evaluating JavaScript language functions, and will gain complete access to JavaScript permissions on the page. This vulnerability is often manifested as an XSS attack.

šŸ”— Read More: Avoid JavaScript eval statements



āœ” 6.16. Prevent evil RegEx from overloading your single thread execution

TL;DR: Regular Expressions, while being handy, pose a real threat to JavaScript applications at large, and the Node.js platform in particular. A user input for text to match might require an outstanding amount of CPU cycles to process. RegEx processing might be inefficient to an extent that a single request that validates 10 words can block the entire event loop for 6 seconds and set the CPU on šŸ”„. For that reason, prefer third-party validation packages like validator.js instead of writing your own Regex patterns, or make use of safe-regex to detect vulnerable regex patterns

Otherwise: Poorly written regexes could be susceptible to Regular Expression DoS attacks that will block the event loop completely. For example, the popular moment package was found vulnerable with malicious RegEx usage in November of 2017

šŸ”— Read More: Prevent malicious RegEx



āœ” 6.17. Avoid module loading using a variable

TL;DR: Avoid requiring/importing another file with a path that was given as parameter due to the concern that it could have originated from user input. This rule can be extended for accessing files in general (i.e. fs.readFile()) or other sensitive resource access with dynamic variables originating from user input. Eslint-plugin-security linter can catch such patterns and warn early enough

Otherwise: Malicious user input could find its way to a parameter that is used to require tampered files, for example, a previously uploaded file on the file system, or access already existing system files.

šŸ”— Read More: Safe module loading



āœ” 6.18. Run unsafe code in a sandbox

TL;DR: When tasked to run external code that is given at run-time (e.g. plugin), use any sort of 'sandbox' execution environment that isolates and guards the main code against the plugin. This can be achieved using a dedicated process (e.g. cluster.fork()), serverless environment or dedicated npm packages that act as a sandbox

Otherwise: A plugin can attack through an endless variety of options like infinite loops, memory overloading, and access to sensitive process environment variables

šŸ”— Read More: Run unsafe code in a sandbox



āœ” 6.19. Take extra care when working with child processes

TL;DR: Avoid using child processes when possible and validate and sanitize input to mitigate shell injection attacks if you still have to. Prefer using child_process.execFile which by definition will only execute a single command with a set of attributes and will not allow shell parameter expansion.

Otherwise: Naive use of child processes could result in remote command execution or shell injection attacks due to malicious user input passed to an unsanitized system command.

šŸ”— Read More: Be cautious when working with child processes



āœ” 6.20. Hide error details from clients

TL;DR: An integrated express error handler hides the error details by default. However, great are the chances that you implement your own error handling logic with custom Error objects (considered by many as a best practice). If you do so, ensure not to return the entire Error object to the client, which might contain some sensitive application details

Otherwise: Sensitive application details such as server file paths, third party modules in use, and other internal workflows of the application which could be exploited by an attacker, could be leaked from information found in a stack trace

šŸ”— Read More: Hide error details from client



āœ” 6.21. Configure 2FA for npm or Yarn

TL;DR: Any step in the development chain should be protected with MFA (multi-factor authentication), npm/Yarn are a sweet opportunity for attackers who can get their hands on some developer's password. Using developer credentials, attackers can inject malicious code into libraries that are widely installed across projects and services. Maybe even across the web if published in public. Enabling 2-factor-authentication in npm leaves almost zero chances for attackers to alter your package code.

Otherwise: Have you heard about the eslint developer whose password was hijacked?



āœ” 6.22. Modify session middleware settings

TL;DR: Each web framework and technology has its known weaknessesā€Š-ā€Štelling an attacker which web framework we use is a great help for them. Using the default settings for session middlewares can expose your app to module- and framework-specific hijacking attacks in a similar way to the X-Powered-By header. Try hiding anything that identifies and reveals your tech stack (E.g. Node.js, express)

Otherwise: Cookies could be sent over insecure connections, and an attacker might use session identification to identify the underlying framework of the web application, as well as module-specific vulnerabilities

šŸ”— Read More: Cookie and session security



āœ” 6.23. Avoid DOS attacks by explicitly setting when a process should crash

TL;DR: The Node process will crash when errors are not handled. Many best practices even recommend to exit even though an error was caught and got handled. Express, for example, will crash on any asynchronous errorā€Š-ā€Šunless you wrap routes with a catch clause. This opens a very sweet attack spot for attackers who recognize what input makes the process crash and repeatedly send the same request. There's no instant remedy for this but a few techniques can mitigate the pain: Alert with critical severity anytime a process crashes due to an unhandled error, validate the input and avoid crashing the process due to invalid user input, wrap all routes with a catch and consider not to crash when an error originated within a request (as opposed to what happens globally)

Otherwise: This is just an educated guess: given many Node.js applications, if we try passing an empty JSON body to all POST requestsā€Š-ā€Ša handful of applications will crash. At that point, we can just repeat sending the same request to take down the applications with ease



āœ” 6.24. Prevent unsafe redirects

TL;DR: Redirects that do not validate user input can enable attackers to launch phishing scams, steal user credentials, and perform other malicious actions.

Otherwise: If an attacker discovers that you are not validating external, user-supplied input, they may exploit this vulnerability by posting specially-crafted links on forums, social media, and other public places to get users to click it.

šŸ”— Read More: Prevent unsafe redirects



āœ” 6.25. Avoid publishing secrets to the npm registry

TL;DR: Precautions should be taken to avoid the risk of accidentally publishing secrets to public npm registries. An .npmignore file can be used to ignore specific files or folders, or the files array in package.json can act as an allow list.

Otherwise: Your project's API keys, passwords or other secrets are open to be abused by anyone who comes across them, which may result in financial loss, impersonation, and other risks.

šŸ”— Read More: Avoid publishing secrets



āœ” 6.26 Inspect for outdated packages

TL;DR: Use your preferred tool (e.g. npm outdated or npm-check-updates) to detect installed outdated packages, inject this check into your CI pipeline and even make a build fail in a severe scenario. For example, a severe scenario might be when an installed package is 5 patch commits behind (e.g. local version is 1.3.1 and repository version is 1.3.8) or it is tagged as deprecated by its author - kill the build and prevent deploying this version

Otherwise: Your production will run packages that have been explicitly tagged by their author as risky



āœ” 6.27. Import built-in modules using the 'node:' protocol

šŸŒŸ #new

TL;DR: Import or require built-in Node.js modules using the 'node protocol' syntax:

import { functionName } from "node:module"; // note that 'node:' prefix

For example:

import { createServer } from "node:http";

This style ensures that there is no ambiguity with global npm packages and makes it clear for the reader that the code refers to a well-trusted official module. This style can be enforced with the eslint rule 'prefer-node-protocol'

Otherwise: Using the import syntax without 'node:' prefix opens the door for typosquatting attacks where one could mistakenly mistype a module name (e.g., 'event' instead of 'events) and get a malicious package that was built only to trick users into installing them




ā¬† Return to top

7. Draft: Performance Best Practices

Our contributors are working on this section. Would you like to join?



āœ” 7.1. Don't block the event loop

TL;DR: Avoid CPU intensive tasks as they will block the mostly single-threaded Event Loop and offload those to a dedicated thread, process or even a different technology based on the context.

Otherwise: As the Event Loop is blocked, Node.js will be unable to handle other request thus causing delays for concurrent users. 3000 users are waiting for a response, the content is ready to be served, but one single request blocks the server from dispatching the results back

šŸ”— Read More: Do not block the event loop




āœ” 7.2. Prefer native JS methods over user-land utils like Lodash

TL;DR: It's often more penalising to use utility libraries like lodash and underscore over native methods as it leads to unneeded dependencies and slower performance. Bear in mind that with the introduction of the new V8 engine alongside the new ES standards, native methods were improved in such a way that it's now about 50% more performant than utility libraries.

Otherwise: You'll have to maintain less performant projects where you could have simply used what was already available or dealt with a few more lines in exchange of a few more files.

šŸ”— Read More: Native over user land utils




ā¬† Return to top

8. Docker Best Practices

šŸ… Many thanks to Bret Fisher from whom we learned many of the following practices



āœ” 8.1 Use multi-stage builds for leaner and more secure Docker images

TL;DR: Use multi-stage build to copy only necessary production artifacts. A lot of build-time dependencies and files are not needed for running your application. With multi-stage builds these resources can be used during build while the runtime environment contains only what's necessary. Multi-stage builds are an easy way to get rid of overweight and security threats.

Otherwise: Larger images will take longer to build and ship, build-only tools might contain vulnerabilities and secrets only meant for the build phase might be leaked.

Example Dockerfile for multi-stage builds

FROM node:14.4.0 AS build

COPY . .
RUN npm ci && npm run build


FROM node:slim-14.4.0

USER node
EXPOSE 8080

COPY --from=build /home/node/app/dist /home/node/app/package.json /home/node/app/package-lock.json ./
RUN npm ci --production

CMD [ "node", "dist/app.js" ]

šŸ”— Read More: Use multi-stage builds




āœ” 8.2. Bootstrap using node command, avoid npm start

TL;DR: Use CMD ['node','server.js'] to start your app, avoid using npm scripts which don't pass OS signals to the code. This prevents problems with child-processes, signal handling, graceful shutdown and having zombie processes

Update: Starting from npm 7, npm claim to pass signals. We follow and will update accordingly

Otherwise: When no signals are passed, your code will never be notified about shutdowns. Without this, it will lose its chance to close properly possibly losing current requests and/or data

Read More: Bootstrap container using node command, avoid npm start




āœ” 8.3. Let the Docker runtime handle replication and uptime

TL;DR: When using a Docker run time orchestrator (e.g., Kubernetes), invoke the Node.js process directly without intermediate process managers or custom code that replicate the process (e.g. PM2, Cluster module). The runtime platform has the highest amount of data and visibility for making placement decision - It knows best how many processes are needed, how to spread them and what to do in case of crashes

Otherwise: Container keeps crashing due to lack of resources will get restarted indefinitely by the process manager. Should Kubernetes be aware of that, it could relocate it to a different roomy instance

šŸ”— Read More: Let the Docker orchestrator restart and replicate processes




āœ” 8.4. Use .dockerignore to prevent leaking secrets

TL;DR: Include a .dockerignore file that filters out common secret files and development artifacts. By doing so, you might prevent secrets from leaking into the image. As a bonus the build time will significantly decrease. Also, ensure not to copy all files recursively rather explicitly choose what should be copied to Docker

Otherwise: Common personal secret files like .env, .aws and .npmrc will be shared with anybody with access to the image (e.g. Docker repository)

šŸ”— Read More: Use .dockerignore




āœ” 8.5. Clean-up dependencies before production

TL;DR: Although Dev-Dependencies are sometimes needed during the build and test life-cycle, eventually the image that is shipped to production should be minimal and clean from development dependencies. Doing so guarantees that only necessary code is shipped and the amount of potential attacks (i.e. attack surface) is minimized. When using multi-stage build (see dedicated bullet) this can be achieved by installing all dependencies first and finally running npm ci --production

Otherwise: Many of the infamous npm security breaches were found within development packages (e.g. eslint-scope)

šŸ”— Read More: Remove development dependencies




āœ” 8.6. Shutdown smartly and gracefully

TL;DR: Handle the process SIGTERM event and clean-up all existing connection and resources. This should be done while responding to ongoing requests. In Dockerized runtimes, shutting down containers is not a rare event, rather a frequent occurrence that happen as part of routine work. Achieving this demands some thoughtful code to orchestrate several moving parts: The load balancer, keep-alive connections, the HTTP server and other resources

Otherwise: Dying immediately means not responding to thousands of disappointed users

šŸ”— Read More: Graceful shutdown




āœ” 8.7. Set memory limits using both Docker and v8

TL;DR: Always configure a memory limit using both Docker and the JavaScript runtime flags. The Docker limit is needed to make thoughtful container placement decision, the --v8's flag max-old-space is needed to kick off the GC on time and prevent under utilization of memory. Practically, set the v8's old space memory to be a just bit less than the container limit

Otherwise: The docker definition is needed to perform thoughtful scaling decision and prevent starving other citizens. Without also defining the v8's limits, it will under utilize the container resources - Without explicit instructions it crashes when utilizing ~50-60% of its host resources

šŸ”— Read More: Set memory limits using Docker only




āœ” 8.8. Plan for efficient caching

TL;DR: Rebuilding a whole docker image from cache can be nearly instantaneous if done correctly. The less updated instructions should be at the top of your Dockerfile and the ones constantly changing (like app code) should be at the bottom.

Otherwise: Docker build will be very long and consume lot of resources even when making tiny changes

šŸ”— Read More: Leverage caching to reduce build times




āœ” 8.9. Use explicit image reference, avoid latest tag

TL;DR: Specify an explicit image digest or versioned label, never refer to latest. Developers are often led to believe that specifying the latest tag will provide them with the most recent image in the repository however this is not the case. Using a digest guarantees that every instance of the service is running exactly the same code.

In addition, referring to an image tag means that the base image is subject to change, as image tags cannot be relied upon for a deterministic install. Instead, if a deterministic install is expected, a SHA256 digest can be used to reference an exact image.

Otherwise: A new version of a base image could be deployed into production with breaking changes, causing unintended application behaviour.

šŸ”— Read More: Understand image tags and use the "latest" tag with caution




āœ” 8.10. Prefer smaller Docker base images

TL;DR: Large images lead to higher exposure to vulnerabilities and increased resource consumption. Using leaner Docker images, such as Slim and Alpine Linux variants, mitigates this issue.

Otherwise: Building, pushing, and pulling images will take longer, unknown attack vectors can be used by malicious actors and more resources are consumed.

šŸ”— Read More: Prefer smaller images




āœ” 8.11. Clean-out build-time secrets, avoid secrets in args

šŸŒŸ #new

TL;DR: Avoid secrets leaking from the Docker build environment. A Docker image is typically shared in multiple environment like CI and a registry that are not as sanitized as production. A typical example is an npm token which is usually passed to a dockerfile as argument. This token stays within the image long after it is needed and allows the attacker indefinite access to a private npm registry. This can be avoided by coping a secret file like .npmrc and then removing it using multi-stage build (beware, build history should be deleted as well) or by using Docker build-kit secret feature which leaves zero traces

Otherwise: Everyone with access to the CI and docker registry will also get access to some precious organization secrets as a bonus

šŸ”— Read More: Clean-out build-time secrets




āœ” 8.12. Scan images for multi layers of vulnerabilities

TL;DR: Besides checking code dependencies vulnerabilities also scan the final image that is shipped to production. Docker image scanners check the code dependencies but also the OS binaries. This E2E security scan covers more ground and verifies that no bad guy injected bad things during the build. Consequently, it is recommended running this as the last step before deployment. There are a handful of free and commercial scanners that also provide CI/CD plugins

Otherwise: Your code might be entirely free from vulnerabilities. However it might still get hacked due to vulnerable version of OS-level binaries (e.g. OpenSSL, TarBall) that are commonly being used by applications

šŸ”— Read More: Scan the entire image before production




āœ” 8.13 Clean NODE_MODULE cache

TL;DR: After installing dependencies in a container remove the local cache. It doesn't make any sense to duplicate the dependencies for faster future installs since there won't be any further installs - A Docker image is immutable. Using a single line of code tens of MB (typically 10-50% of the image size) are shaved off

Otherwise: The image that will get shipped to production will weigh 30% more due to files that will never get used

šŸ”— Read More: Clean NODE_MODULE cache




āœ” 8.14. Generic Docker practices

TL;DR: This is a collection of Docker advice that is not related directly to Node.js - the Node implementation is not much different than any other language. Click read more to skim through.

šŸ”— Read More: Generic Docker practices




āœ” 8.15. Lint your Dockerfile

šŸŒŸ #new

TL;DR: Linting your Dockerfile is an important step to identify issues in your Dockerfile which differ from best practices. By checking for potential flaws using a specialised Docker linter, performance and security improvements can be easily identified, saving countless hours of wasted time or security issues in production code.

Otherwise: Mistakenly the Dockerfile creator left Root as the production user, and also used an image from unknown source repository. This could be avoided with with just a simple linter.

šŸ”— Read More: Lint your Dockerfile




ā¬† Return to top

Milestones

To maintain this guide and keep it up to date, we are constantly updating and improving the guidelines and best practices with the help of the community. You can follow our milestones and join the working groups if you want to contribute to this project


Translations

All translations are contributed by the community. We will be happy to get any help with either completed, ongoing or new translations!

Completed translations

Translations in progress



Steering Committee

Meet the steering committee members - the people who work together to provide guidance and future direction to the project. In addition, each member of the committee leads a project tracked under our GitHub projects.

Yoni Goldberg

Independent Node.js consultant who works with customers in the USA, Europe, and Israel on building large-scale Node.js applications. Many of the best practices above were first published at goldbergyoni.com. Reach Yoni at @goldbergyoni or me@goldbergyoni.com


Josh Hemphill

Josh Hemphill

Full Stack Software Engineer / Developer specializing in Security, DevOps/DevSecOps, and ERP Integrations.


Raz Luvaton

Raz Luvaton

Full Stack Developer who knows how to exit from Vim and loves Architecture, Virtualization and Security.


Contributing

If you've ever wanted to contribute to open source, now is your chance! See the contributing docs for more information.

Contributors āœØ

Thanks goes to these wonderful people who have contributed to this repository!

Kevin Rambaud
Kevin Rambaud

šŸ–‹
Michael Fine
Michael Fine

šŸ–‹
Shreya Dahal
Shreya Dahal

šŸ–‹
Matheus Cruz Rocha
Matheus Cruz Rocha

šŸ–‹
Yog Mehta
Yog Mehta

šŸ–‹
Kudakwashe Paradzayi
Kudakwashe Paradzayi

šŸ–‹
t1st3
t1st3

šŸ–‹
mulijordan1976
mulijordan1976

šŸ–‹
Matan Kushner
Matan Kushner

šŸ–‹
Fabio Hiroki
Fabio Hiroki

šŸ–‹
James Sumners
James Sumners

šŸ–‹
Dan Gamble
Dan Gamble

šŸ–‹
PJ Trainor
PJ Trainor

šŸ–‹
Remek Ambroziak
Remek Ambroziak

šŸ–‹
Yoni Jah
Yoni Jah

šŸ–‹
Misha Khokhlov
Misha Khokhlov

šŸ–‹
Evgeny Orekhov
Evgeny Orekhov

šŸ–‹
-
-

šŸ–‹
Isaac Halvorson
Isaac Halvorson

šŸ–‹
Vedran Karačić
Vedran Karačić

šŸ–‹
lallenlowe
lallenlowe

šŸ–‹
Nathan Wells
Nathan Wells

šŸ–‹
Paulo Reis
Paulo Reis

šŸ–‹
syzer
syzer

šŸ–‹
David Sancho
David Sancho

šŸ–‹
Robert Manolea
Robert Manolea

šŸ–‹
Xavier Ho
Xavier Ho

šŸ–‹
Aaron
Aaron

šŸ–‹
Jan Charles Maghirang Adona
Jan Charles Maghirang Adona

šŸ–‹
Allen
Allen

šŸ–‹
Leonardo Villela
Leonardo Villela

šŸ–‹
Michał Załęcki
Michał Załęcki

šŸ–‹
Chris Nicola
Chris Nicola

šŸ–‹
Alejandro Corredor
Alejandro Corredor

šŸ–‹
cwar
cwar

šŸ–‹
Yuwei
Yuwei

šŸ–‹
Utkarsh Bhatt
Utkarsh Bhatt

šŸ–‹
Duarte Mendes
Duarte Mendes

šŸ–‹
Jason Kim
Jason Kim

šŸ–‹
Mitja O.
Mitja O.

šŸ–‹
Sandro Miguel Marques
Sandro Miguel Marques

šŸ–‹
Gabe
Gabe

šŸ–‹
Ron Gross
Ron Gross

šŸ–‹
Valeri Karpov
Valeri Karpov

šŸ–‹
Sergio Bernal
Sergio Bernal

šŸ–‹
Nikola Telkedzhiev
Nikola Telkedzhiev

šŸ–‹
Vitor Godoy
Vitor Godoy

šŸ–‹
Manish Saraan
Manish Saraan

šŸ–‹
Sangbeom Han
Sangbeom Han

šŸ–‹
blackmatch
blackmatch

šŸ–‹
Joe Reeve
Joe Reeve

šŸ–‹
Ryan Busby
Ryan Busby

šŸ–‹
Iman Mohamadi
Iman Mohamadi

šŸ–‹
Sergii Paryzhskyi
Sergii Paryzhskyi

šŸ–‹
Kapil Patel
Kapil Patel

šŸ–‹
čæ·ęø”
čæ·ęø”

šŸ–‹
Hozefa
Hozefa

šŸ–‹
Ethan
Ethan

šŸ–‹
Sam
Sam

šŸ–‹
Arlind
Arlind

šŸ–‹
Teddy Toussaint
Teddy Toussaint

šŸ–‹
Lewis
Lewis

šŸ–‹
Gabriel Lidenor
Gabriel Lidenor

šŸ–‹
Roman
Roman

šŸ–‹
Francozeira
Francozeira

šŸ–‹
Invvard
Invvard

šŸ–‹
RĆ“mulo Garofalo
RĆ“mulo Garofalo

šŸ–‹
Tho Q Luong
Tho Q Luong

šŸ–‹
Burak Shen
Burak Shen

šŸ–‹
Martin Muzatko
Martin Muzatko

šŸ–‹
Jared Collier
Jared Collier

šŸ–‹
Hilton Meyer
Hilton Meyer

šŸ–‹
ChangJoo Park(ė°•ģ°½ģ£¼)
ChangJoo Park(ė°•ģ°½ģ£¼)

šŸ–‹
Masahiro Sakaguchi
Masahiro Sakaguchi

šŸ–‹
Keith Holliday
Keith Holliday

šŸ–‹
coreyc
coreyc

šŸ–‹
Maximilian Berkmann
Maximilian Berkmann

šŸ–‹
Douglas Mariano Valero
Douglas Mariano Valero

šŸ–‹
Marcelo Melo
Marcelo Melo

šŸ–‹
Mehmet Perk
Mehmet Perk

šŸ–‹
ryan ouyang
ryan ouyang

šŸ–‹
Shabeer
Shabeer

šŸ–‹
Eduard Kyvenko
Eduard Kyvenko

šŸ–‹
Deyvison Rocha
Deyvison Rocha

šŸ–‹
George Mamer
George Mamer

šŸ–‹
Konstantinos Leimonis
Konstantinos Leimonis

šŸ–‹
Oliver Lluberes
Oliver Lluberes

šŸŒ
Tien Do
Tien Do

šŸ–‹
Ranvir Singh
Ranvir Singh

šŸ–‹
Vadim Nicolaev
Vadim Nicolaev

šŸ–‹ šŸŒ
German Gamboa Gonzalez
German Gamboa Gonzalez

šŸ–‹
Hafez
Hafez

šŸ–‹
Chandiran
Chandiran

šŸ–‹
VinayaSathyanarayana
VinayaSathyanarayana

šŸ–‹
Kim Kern
Kim Kern

šŸ–‹
Kenneth Freitas
Kenneth Freitas

šŸ–‹
songe
songe

šŸ–‹
Kirill Shekhovtsov
Kirill Shekhovtsov

šŸ–‹
Serge
Serge

šŸ–‹
keyrwinz
keyrwinz

šŸ–‹
Dmitry Nikitenko
Dmitry Nikitenko

šŸ–‹
bushuai
bushuai

šŸ‘€ šŸ–‹
Benjamin Gruenbaum
Benjamin Gruenbaum

šŸ–‹
Ezequiel
Ezequiel

šŸŒ
Juan JosƩ Rodrƭguez
Juan JosƩ Rodrƭguez

šŸŒ
Or Bin
Or Bin

šŸ–‹
Andreo Vieira
Andreo Vieira

šŸ–‹
Michael Solomon
Michael Solomon

šŸ–‹
Jimmy Callin
Jimmy Callin

šŸ–‹
Siddharth
Siddharth

šŸ–‹
Ryan Smith
Ryan Smith

šŸ–‹
Tom Boettger
Tom Boettger

šŸ–‹
JoaquĆ­n Ormaechea
JoaquĆ­n Ormaechea

šŸŒ
dfrzuz
dfrzuz

šŸŒ
Victor Homyakov
Victor Homyakov

šŸ–‹
Josh
Josh

šŸ–‹ šŸ›”ļø
Alec Francis
Alec Francis

šŸ–‹
arjun6610
arjun6610

šŸ–‹
Jan Osch
Jan Osch

šŸ–‹
Thiago Rotondo Sampaio
Thiago Rotondo Sampaio

šŸŒ
Alexsey
Alexsey

šŸ–‹
Luis A. Acurero
Luis A. Acurero

šŸŒ
Lucas Romano
Lucas Romano

šŸŒ
Denise Case
Denise Case

šŸ–‹
Nick Ribal
Nick Ribal

šŸ–‹ šŸ‘€
0xflotus
0xflotus

šŸ–‹
Jonathan Chen
Jonathan Chen

šŸ–‹
Dilan Srilal
Dilan Srilal

šŸ–‹
vladthelittleone
vladthelittleone

šŸŒ
Nik Osvalds
Nik Osvalds

šŸ–‹
Daniel Kiss
Daniel Kiss

šŸ“–
Forresst
Forresst

šŸ–‹
Jonathan Svenheden
Jonathan Svenheden

šŸ–‹
AustrisC
AustrisC

šŸ–‹
kyeongtae kim
kyeongtae kim

šŸŒ
007
007

šŸ–‹
Ane Diaz de Tuesta
Ane Diaz de Tuesta

šŸŒ šŸ–‹
YukiOta
YukiOta

šŸŒ
Frazer Smith
Frazer Smith

šŸ–‹
Raz Luvaton
Raz Luvaton

šŸ–‹
Yuta Azumi
Yuta Azumi

šŸ–‹
andrewjbarbour
andrewjbarbour

šŸ–‹
mr
mr

šŸ–‹
Aleksandar
Aleksandar

šŸ–‹
Owl
Owl

šŸ–‹
Yedidya Schwartz
Yedidya Schwartz

šŸ–‹ šŸ’”
ari
ari

šŸ–‹
Thomas Kƶnig
Thomas Kƶnig

šŸ–‹
Kalle LƤmsƤ
Kalle LƤmsƤ

šŸ–‹
Wyatt
Wyatt

šŸ–‹
KHADIR Tayeb
KHADIR Tayeb

šŸ–‹
Shankar Regmi
Shankar Regmi

šŸ–‹
Shubham
Shubham

šŸ–‹
Lucas Alves
Lucas Alves

šŸ–‹
Benjamin
Benjamin

šŸ–‹
Yeoh Joer
Yeoh Joer

šŸ–‹
Miigon
Miigon

šŸ–‹
Rostislav Bogorad
Rostislav Bogorad

šŸ–‹
Flouse
Flouse

šŸ–‹
Tarantini Pereira
Tarantini Pereira

šŸ–‹
Kazuki Matsuo
Kazuki Matsuo

šŸ–‹
Adam Smith
Adam Smith

šŸ–‹
Dohyeon Ko
Dohyeon Ko

šŸ–‹
Vladislav Legkov
Vladislav Legkov

šŸ–‹
Kerollos Magdy
Kerollos Magdy

šŸ–‹
Erez Lieberman
Erez Lieberman

šŸ–‹
Breno Macedo
Breno Macedo

šŸ–‹
Fernando Flores
Fernando Flores

šŸŒ
Rafael Brito
Rafael Brito

šŸŒ
Emiliano Peralta
Emiliano Peralta

šŸŒ
Shin, SJ
Shin, SJ

šŸ–‹
Benjamin Forster
Benjamin Forster

šŸ–‹
Daniele Fedeli
Daniele Fedeli

šŸ–‹
djob195
djob195

šŸ–‹
antspk
antspk

šŸ–‹
ģ •ģ§„ģ˜
ģ •ģ§„ģ˜

šŸ–‹
kkk-cashwalk
kkk-cashwalk

šŸ–‹
apainintheneck
apainintheneck

šŸ–‹
Fajar Budhi Iswanda
Fajar Budhi Iswanda

šŸ–‹
ģ“ģ£¼ķ˜ø
ģ“ģ£¼ķ˜ø

šŸ–‹
Singh
Singh

šŸ–‹
Alex Dumitru
Alex Dumitru

šŸ–‹
Anton Lykhatskyi
Anton Lykhatskyi

šŸ–‹
sangwonlee
sangwonlee

šŸ–‹
Eugenio Berretta
Eugenio Berretta

šŸ–‹
soranakk
soranakk

šŸ–‹
ź³ ģ¤€ģ˜
ź³ ģ¤€ģ˜

šŸ–‹ šŸ’»
Guilherme Portella
Guilherme Portella

šŸ–‹
AndrƩ Esser
AndrƩ Esser

šŸ–‹
Scc
Scc

šŸŒ
Mauro Accornero
Mauro Accornero

šŸ–‹
no-yan
no-yan

šŸ–‹
hodbauer
hodbauer

šŸŒ

Steering Committee Emeriti

Bruno Scheufler

šŸ’» full-stack web engineer, Node.js & GraphQL enthusiast


Kyle Martin

Full Stack Developer & Site Reliability Engineer based in New Zealand, interested in web application security, and architecting and building Node.js applications to perform at global scale.


Kevyn Bruyere

Independent full-stack developer with a taste for Ops and automation.


Sagir Khan

Deep specialist in JavaScript and its ecosystem ā€” React, Node.js, TypeScript, GraphQL, MongoDB, pretty much anything that involves JS/JSON in any layer of the system ā€” building products using the web platform for the worldā€™s most recognized brands. Individual Member of the Node.js Foundation.