Archives: FAQs

Q. What is clustering mode and when should I use it?

A: In cluster mode, PM2 spawns multiple instances of your Node.js app (workers) that share server ports using Node’s cluster module. This allows better utilization of multi-core machines and improved throughput. Use clustering when your application is CPU-bound or when handling many concurrent requests.

Q. How can I manage and monitor my application using PM2 commands?

Answer: Basic commands: pm2 list: list running processes pm2 stop <app> or pm2 delete <app>: stop or remove pm2 restart <app> or pm2 reload <app>: restart or reload without downtime pm2 logs <app>: view aggregated logs pm2 monit: open monitoring dashboard pm2 startup: generate startup scripts so processes start on system boot pm2 scale <app> […]

Q. What is PM2 and why use it with Node.js?

A: PM2 is a production process manager for Node.js that runs your apps as daemons, ensures they stay running (restarts on crash), provides clustering, monitoring, log management, and can launch apps on system startup. It helps avoid downtime and simplifies process control.

Q. What are the benefits and trade-offs of using standalone components?

A: Benefits: Less boilerplate (no NgModule required), better tree-shaking, simpler component dependencies, more modularity. Trade-offs: It may require migrating existing module-based code gradually. Some tooling or libraries still expect modules. Also, careful management of imports is needed as each standalone component must list its needed dependencies.

Q. How do I create a standalone component?

You can generate a component with the –standalone flag (e.g. ng generate component my-comp –standalone). In the component decorator, add standalone: true, and import required modules (like CommonModule) in the imports array within that decorator.

Q. How do I structure test files and run only subsets of tests?

A: A common pattern: place test files in a test folder, name them with .spec.js or .test.js, mirror your code directory structure, and import functions or modules to test. Mocha allows filtering via patterns (e.g. mocha test/user*.js). You can also use .only or .skip flags on describe or it to run or skip specific suites. […]

Back To Top