Modern Node.js applications expose functionality through many different invocation mechanisms. A piece of business logic might be executed directly inside the process, triggered through an HTTP endpoint, run as a CLI command, or invoked across processes using RPC or messaging.
Choosing how code is executed is often as important as what the code does, because the invocation mechanism defines the boundary of execution, affecting performance, reliability, isolation, and maintainability.
This article explores common code-invocation mechanisms in Node.js, their advantages and disadvantages, and how to reason about them in real-world scenarios—such as seeding a database for automated tests in a NestJS application.