Loopar provides comprehensive process control commands to manage your application lifecycle in production environments.
Start Command
Start your Loopar application in production mode.
Start All Sites
Starts the core site and all configured sites in production mode.
Start Specific Site
Starts only the specified site.
The name of the site to start (corresponds to the directory name in sites/)
Source Code
start ( siteName ) {
if ( ! siteName ) {
console . log ( chalk . cyan ( 'Starting core site.' ));
pm2Command (
`node bin/ensure-site.js && pm2 start bin/loopar.ecosystem.config.mjs --namespace ${ namespace } --silent && node bin/loopar-status.js --env production`
);
} else {
console . log ( chalk . cyan ( `Starting ${ siteName } ...` ));
pm2Command (
`node bin/ensure-site.js && pm2 start bin/loopar.ecosystem.config.mjs --namespace ${ namespace } --only ${ siteName } --silent && node bin/loopar-status.js --env production`
);
}
}
Examples
Start All
Start Specific Site
loopar start
# Starting core site.
# ✓ Sites started successfully
The start command ensures the site exists before starting and displays a status table after successful startup.
Stop Command
Gracefully stop running Loopar processes.
Stop All Sites
Stops all running sites under the current project namespace.
Stop Specific Site
Stops only the specified site.
Source Code
stop ( siteName ) {
if ( ! siteName ) {
console . log ( chalk . yellow ( 'Stopping all sites...' ));
pm2Command ( `pm2 stop all --namespace ${ namespace } ` );
} else {
const processName = getProcessName ( siteName );
console . log ( chalk . yellow ( `Stopping ${ siteName } ...` ));
pm2Command ( `pm2 stop ${ processName } --namespace ${ namespace } ` );
}
}
Examples
Stop All
Stop Specific Site
loopar stop
# Stopping all sites...
# [PM2] Stopping all processes
Stopping a site does not remove it from PM2. The process remains in PM2’s process list and can be restarted. Use delete to completely remove a process.
Restart Command
Restart running processes with zero-downtime for configuration updates or code changes.
Restart All Sites
Restarts all sites under the current project namespace.
Restart Specific Site
loopar restart < siteNam e >
Restarts only the specified site.
Source Code
restart ( siteName ) {
if ( ! siteName ) {
console . log ( chalk . cyan ( 'Restarting all sites...' ));
pm2Command ( `pm2 restart all --namespace ${ namespace } ` );
} else {
const processName = getProcessName ( siteName );
console . log ( chalk . cyan ( `Restarting ${ siteName } ...` ));
pm2Command ( `pm2 restart ${ processName } --namespace ${ namespace } ` );
}
}
When to Restart
Restart your application when:
Configuration Changes - Updated .env files or settings
Code Updates - Deployed new code to production
Dependency Updates - Installed or updated npm packages
Memory Leaks - As a temporary fix while debugging
Performance Issues - To clear cached data and reset state
Examples
Restart All
Restart Specific Site
loopar restart
# Restarting all sites...
# [PM2] Restarting all processes
PM2 performs graceful restarts by default, ensuring no downtime during the restart process.
Delete Command
Remove processes from PM2’s process list. This is a destructive operation that cannot be undone.
Delete All Sites
Removes all sites from PM2 under the current project namespace.
Delete Specific Site
Removes only the specified site from PM2.
Source Code
delete ( siteName ) {
if ( ! siteName ) {
console . log ( chalk . red ( 'Deleting all sites from PM2...' ));
pm2Command ( `pm2 delete all --namespace ${ namespace } ` );
} else {
const processName = getProcessName ( siteName );
console . log ( chalk . red ( `Deleting ${ siteName } from PM2...` ));
pm2Command ( `pm2 delete ${ processName } --namespace ${ namespace } ` );
}
}
Examples
Delete All
Delete Specific Site
loopar delete
# Deleting all sites from PM2...
# [PM2] Deleting all processes
The delete command removes the process from PM2’s management but does not delete any files or data. Site directories in sites/ remain intact.
When to Delete
Use delete when:
Cleaning Up - Removing old or unused sites
Troubleshooting - Clearing PM2 process list
Namespace Conflicts - Resolving process naming issues
Fresh Start - Before redeploying or reconfiguring
Process Naming
Processes are named using the pattern:
function getProcessName ( siteName ) {
return ` ${ projectName } - ${ siteName } ` ;
}
For example, in a project named my-app:
loopar start dev creates process my-app-dev
loopar start production creates process my-app-production
Best Practices
Development Workflow
# Start development
loopar dev
# Make changes...
# Restart to apply changes
loopar restart dev
# View logs for debugging
loopar logs dev
# Stop when done
loopar stop dev
Production Deployment
# Deploy new code
git pull origin main
npm install
# Restart to apply updates
loopar restart production
# Verify status
loopar status
# Monitor logs
loopar logs production
Clean Shutdown
# Stop all processes
loopar stop
# Remove from PM2
loopar delete
# Verify cleanup
pm2 list
Error Handling
If a command fails, error messages are displayed in red:
function pm2Command ( cmd , silent = false ) {
try {
const result = execSync ( cmd , {
stdio: silent ? 'pipe' : 'inherit' ,
encoding: 'utf8'
});
return result ;
} catch ( err ) {
if ( ! silent ) {
console . error ( chalk . red ( `Error: ${ err } ` ));
}
return null ;
}
}
Next Steps
View Status Check the status of all running processes
Monitor Logs View real-time logs for debugging and monitoring
Development Mode Learn about the dev command for local development
PM2 Commands Explore advanced PM2 commands and features