or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

cli-commands.mdconfiguration.mddocker-integration.mdindex.mdmodule-management.mdmonitoring.mdprocess-management.mdtypescript-definitions.mdversion-control.md

cli-commands.mddocs/

0

# CLI Commands

1

2

Comprehensive command-line interface providing 68 commands for process management, monitoring, configuration, and system integration. PM2's CLI provides both simple operations and advanced features for production environments.

3

4

## CLI Binaries

5

6

PM2 provides multiple CLI executables for different use cases:

7

8

```bash { .api }

9

# Main CLI - Full feature set

10

pm2 <command> [options]

11

12

# Development CLI - Enhanced debugging

13

pm2-dev <script> [options]

14

15

# Container runtime - Optimized for Docker

16

pm2-docker <script|config> [options]

17

pm2-runtime <script|config> [options]

18

```

19

20

## Core Process Management

21

22

Essential commands for managing application processes.

23

24

### Start Applications

25

26

```bash { .api }

27

# Start application with automatic name detection

28

pm2 start <script>

29

30

# Start with custom name

31

pm2 start <script> --name <app_name>

32

33

# Start in cluster mode with all CPU cores

34

pm2 start <script> -i max

35

36

# Start with specific number of instances

37

pm2 start <script> -i <number>

38

39

# Start from ecosystem file

40

pm2 start ecosystem.config.js

41

42

# Start with environment

43

pm2 start <script> --env production

44

45

# Start with custom options

46

pm2 start <script> --watch --ignore-watch="node_modules"

47

```

48

49

**Usage Examples:**

50

51

```bash

52

# Start simple application

53

pm2 start app.js

54

55

# Start cluster application

56

pm2 start server.js --name "web-server" -i max

57

58

# Start with environment variables

59

pm2 start api.js --name "api" --env NODE_ENV=production --env PORT=3000

60

61

# Start from ecosystem configuration

62

pm2 start ecosystem.config.js --env production

63

64

# Start with file watching

65

pm2 start dev-server.js --watch --ignore-watch="logs"

66

```

67

68

### Stop Applications

69

70

```bash { .api }

71

# Stop specific application

72

pm2 stop <name|id>

73

74

# Stop all applications

75

pm2 stop all

76

77

# Stop multiple applications

78

pm2 stop app1 app2 app3

79

```

80

81

**Usage Examples:**

82

83

```bash

84

pm2 stop my-app

85

pm2 stop 0

86

pm2 stop all

87

```

88

89

### Restart Applications

90

91

```bash { .api }

92

# Restart specific application

93

pm2 restart <name|id>

94

95

# Restart all applications

96

pm2 restart all

97

98

# Restart with environment update

99

pm2 restart <name|id> --update-env

100

```

101

102

**Usage Examples:**

103

104

```bash

105

pm2 restart my-app

106

pm2 restart all --update-env

107

```

108

109

### Reload Applications (Zero-Downtime)

110

111

```bash { .api }

112

# Zero-downtime reload (cluster mode only)

113

pm2 reload <name|id>

114

115

# Reload all cluster applications

116

pm2 reload all

117

118

# Reload with environment update

119

pm2 reload <name|id> --update-env

120

```

121

122

**Usage Examples:**

123

124

```bash

125

pm2 reload web-server

126

pm2 reload all --update-env

127

```

128

129

### Delete Applications

130

131

```bash { .api }

132

# Delete specific application

133

pm2 delete <name|id>

134

135

# Delete all applications

136

pm2 delete all

137

138

# Delete multiple applications

139

pm2 delete app1 app2

140

```

141

142

**Usage Examples:**

143

144

```bash

145

pm2 delete old-app

146

pm2 delete 0 1 2

147

pm2 delete all

148

```

149

150

### Scale Applications

151

152

```bash { .api }

153

# Scale application to specific number of instances

154

pm2 scale <name> <number>

155

156

# Scale to maximum CPU cores

157

pm2 scale <name> max

158

```

159

160

**Usage Examples:**

161

162

```bash

163

pm2 scale web-app 4

164

pm2 scale api max

165

```

166

167

## Process Information

168

169

Commands for retrieving process information and status.

170

171

### List Processes

172

173

```bash { .api }

174

# List all processes (table format)

175

pm2 list

176

pm2 ls

177

pm2 ps

178

pm2 status

179

180

# Simple list format

181

pm2 slist

182

183

# JSON format

184

pm2 jlist

185

186

# Pretty formatted list

187

pm2 prettylist

188

```

189

190

### Process Details

191

192

```bash { .api }

193

# Describe specific process

194

pm2 describe <name|id>

195

pm2 desc <name|id>

196

pm2 info <name|id>

197

pm2 show <name|id>

198

199

# Get process ID

200

pm2 id <name>

201

202

# Get process PID

203

pm2 pid [app_name]

204

```

205

206

**Usage Examples:**

207

208

```bash

209

pm2 describe my-app

210

pm2 pid web-server

211

pm2 id api-service

212

```

213

214

## Monitoring

215

216

Real-time monitoring and log management commands.

217

218

### Process Monitoring

219

220

```bash { .api }

221

# Launch monitoring interface

222

pm2 monit

223

pm2 imonit

224

225

# Launch dashboard

226

pm2 dashboard

227

228

# System monitoring

229

pm2 sysmonit

230

```

231

232

### Log Management

233

234

```bash { .api }

235

# Stream logs from all processes

236

pm2 logs

237

238

# Stream logs from specific process

239

pm2 logs <name|id>

240

241

# Stream logs with timestamp

242

pm2 logs --timestamp

243

244

# Stream specific number of lines

245

pm2 logs --lines <number>

246

247

# Flush all logs

248

pm2 flush

249

250

# Reload/rotate logs

251

pm2 reloadLogs

252

253

# Setup log rotation

254

pm2 logrotate

255

```

256

257

**Usage Examples:**

258

259

```bash

260

pm2 logs my-app --lines 100

261

pm2 logs --timestamp

262

pm2 flush all

263

```

264

265

## Configuration Management

266

267

Commands for managing PM2 configuration and settings.

268

269

### Configuration Operations

270

271

```bash { .api }

272

# Get all configuration

273

pm2 conf

274

275

# Get specific configuration value

276

pm2 get <key>

277

278

# Set configuration value

279

pm2 set <key> <value>

280

281

# Set multiple values

282

pm2 multiset <values>

283

284

# Remove configuration value

285

pm2 unset <key>

286

```

287

288

**Usage Examples:**

289

290

```bash

291

pm2 get pm2_home

292

pm2 set log-date-format "YYYY-MM-DD HH:mm:ss"

293

pm2 multiset "instances=max exec-mode=cluster"

294

pm2 unset log-date-format

295

```

296

297

### State Persistence

298

299

```bash { .api }

300

# Save current process list

301

pm2 dump

302

303

# Restore saved processes

304

pm2 resurrect

305

306

# Clear saved process list

307

pm2 cleardump

308

309

# Reset process counters

310

pm2 reset <name|id|all>

311

```

312

313

**Usage Examples:**

314

315

```bash

316

pm2 dump

317

pm2 resurrect

318

pm2 reset my-app

319

```

320

321

## System Integration

322

323

Commands for system-level operations and daemon management.

324

325

### Daemon Management

326

327

```bash { .api }

328

# Kill PM2 daemon and all processes

329

pm2 kill

330

331

# Test daemon connection

332

pm2 ping

333

334

# Update PM2 daemon

335

pm2 update

336

pm2 updatePM2

337

```

338

339

### Startup Scripts

340

341

```bash { .api }

342

# Generate startup script

343

pm2 startup [platform]

344

345

# Remove startup script

346

pm2 unstartup [platform]

347

348

# Auto-detect platform and generate startup

349

pm2 startup

350

```

351

352

**Usage Examples:**

353

354

```bash

355

pm2 startup systemd

356

pm2 startup ubuntu

357

pm2 unstartup

358

```

359

360

## Module Management

361

362

Commands for installing and managing PM2 modules.

363

364

### Module Operations

365

366

```bash { .api }

367

# Install module

368

pm2 install <module_name>

369

370

# Install from Git URL

371

pm2 install <git_url>

372

373

# Uninstall module

374

pm2 uninstall <module_name>

375

376

# Update module

377

pm2 module:update <module_name>

378

379

# Generate module template

380

pm2 module:generate [app_name]

381

382

# Package module

383

pm2 package [target]

384

385

# Publish module

386

pm2 publish [folder]

387

```

388

389

**Usage Examples:**

390

391

```bash

392

pm2 install pm2-logrotate

393

pm2 install git+https://github.com/username/pm2-module.git

394

pm2 uninstall pm2-server-monit

395

pm2 module:update pm2-logrotate

396

```

397

398

## Development and Debugging

399

400

Commands for development, debugging, and performance analysis.

401

402

### Development Mode

403

404

```bash { .api }

405

# Start in development mode with auto-restart

406

pm2-dev <script>

407

408

# Development mode with options

409

pm2-dev <script> --watch --ignore-watch="node_modules"

410

```

411

412

### Debugging and Profiling

413

414

```bash { .api }

415

# Inspect process for debugging

416

pm2 inspect <name>

417

418

# CPU profiling

419

pm2 profile:cpu [time]

420

421

# Memory profiling

422

pm2 profile:mem [time]

423

424

# Attach to process

425

pm2 attach <pm_id> [separator]

426

427

# Send line to process stdin

428

pm2 send <pm_id> <line>

429

430

# Trigger custom action

431

pm2 trigger <id|name|namespace|all> <action> [params]

432

433

# Send signal to process

434

pm2 sendSignal <signal> <pm2_id|name>

435

```

436

437

**Usage Examples:**

438

439

```bash

440

pm2 inspect my-app

441

pm2 profile:cpu 30

442

pm2 profile:mem

443

pm2 trigger my-app graceful-shutdown

444

pm2 sendSignal SIGUSR1 my-app

445

```

446

447

### Environment Management

448

449

```bash { .api }

450

# Show process environment

451

pm2 env <id>

452

453

# Get process environment variables

454

pm2 env <name|id>

455

```

456

457

## PM2+ Integration

458

459

Commands for integrating with PM2+ cloud monitoring service.

460

461

### PM2+ Operations

462

463

```bash { .api }

464

# Link to PM2+

465

pm2 link [secret] [public] [name]

466

467

# Unlink from PM2+

468

pm2 unlink

469

470

# Login to PM2+

471

pm2 login

472

473

# Logout from PM2+

474

pm2 logout

475

476

# PM2+ operations

477

pm2 plus [command] [option]

478

479

# Open PM2+ dashboard

480

pm2 open

481

482

# Monitor process

483

pm2 monitor [name]

484

485

# Unmonitor process

486

pm2 unmonitor [name]

487

```

488

489

**Usage Examples:**

490

491

```bash

492

pm2 link abc123 def456 my-server

493

pm2 unlink

494

pm2 open

495

```

496

497

## Utility Commands

498

499

Additional utility commands for various operations.

500

501

### Static File Serving

502

503

```bash { .api }

504

# Serve current directory

505

pm2 serve

506

507

# Serve specific directory and port

508

pm2 serve <path> [port]

509

510

# Serve with options

511

pm2 serve <path> <port> --spa

512

```

513

514

**Usage Examples:**

515

516

```bash

517

pm2 serve ./public 8080

518

pm2 serve ./dist 3000 --spa

519

```

520

521

### Deployment

522

523

```bash { .api }

524

# Deploy application

525

pm2 deploy <file|environment>

526

527

# Pull repository changes

528

pm2 pull <name> [commit_id]

529

530

# Navigate version control

531

pm2 forward <name>

532

pm2 backward <name>

533

534

# Deep update process

535

pm2 deepUpdate

536

```

537

538

### Ecosystem Management

539

540

```bash { .api }

541

# Generate ecosystem file

542

pm2 ecosystem [mode]

543

544

# Create ecosystem template

545

pm2 create

546

547

# Start from ecosystem with specific environment

548

pm2 start ecosystem.config.js --env production

549

```

550

551

**Usage Examples:**

552

553

```bash

554

pm2 ecosystem simple

555

pm2 ecosystem

556

pm2 create

557

```

558

559

### Miscellaneous

560

561

```bash { .api }

562

# Show usage examples

563

pm2 examples

564

565

# Generate diagnostic report

566

pm2 report

567

568

# Auto-install dependencies

569

pm2 autoinstall

570

```

571

572

## Common Command Options

573

574

PM2 commands support various options that can be combined:

575

576

### Global Options

577

578

```bash { .api }

579

--name <name> # Process name

580

--namespace <namespace> # Process namespace

581

-i, --instances <number> # Number of instances

582

--exec-mode <mode> # Execution mode (fork|cluster)

583

--watch # Enable file watching

584

--ignore-watch <pattern> # Ignore watch patterns

585

--max-memory-restart <mem> # Memory restart threshold

586

--env <environment> # Environment to use

587

--cwd <path> # Working directory

588

--log <path> # Log file path

589

--output <path> # Stdout log file

590

--error <path> # Stderr log file

591

--pid <path> # PID file path

592

--merge-logs # Merge cluster logs

593

--log-date-format <fmt> # Log timestamp format

594

--restart-delay <delay> # Restart delay in ms

595

--time # Prefix logs with time

596

--no-autorestart # Disable auto restart

597

--cron <pattern> # Cron restart pattern

598

--no-daemon # Do not run in daemon mode

599

```

600

601

### Start Command Options

602

603

```bash { .api }

604

pm2 start app.js \

605

--name "my-app" \

606

--instances max \

607

--exec-mode cluster \

608

--watch \

609

--ignore-watch "node_modules" \

610

--max-memory-restart 1G \

611

--env production \

612

--log-date-format "YYYY-MM-DD HH:mm:ss Z" \

613

--merge-logs

614

```

615

616

## Exit Codes

617

618

PM2 CLI commands return standard exit codes:

619

620

- `0` - Success

621

- `1` - General error

622

- `2` - Connection error

623

- `3` - Process not found

624

- `4` - Configuration error