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. How do I install and start using PM2 for my Node.js project?
A: Install via npm install pm2 –save (or globally via npm install -g pm2). In your project folder, run pm2 start app.js (or pm2 start index.js) to launch the process. You can name the process using –name.
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. Can I gradually migrate an existing Angular app to use standalone components?
A: Yes — Angular supports hybrid use of modules and standalone components. You can incrementally convert components to standalone by adding standalone: true, moving their dependencies into the imports of the component, and removing them from modules, then using bootstrapApplication when all is migrated.
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 to use a standalone component inside another component or module?
Answer: Inside another standalone component: include it in the imports array of that component. Inside a module-based component: import the standalone component in the module’s imports.
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. What are standalone components in Angular 14 and how are they different from module-based components?
A: Standalone components are components declared with standalone: true in their @Component decorator so they don’t need to be declared in an NgModule. They manage their own imports directly. This reduces boilerplate and allows coexisting use of module-based and standalone components.
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. […]