Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@pm2/js-api

Package Overview
Dependencies
Maintainers
2
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pm2/js-api

PM2.io API Client for Javascript

  • 0.8.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.4M
increased by2.2%
Maintainers
2
Weekly downloads
 
Created

What is @pm2/js-api?

The @pm2/js-api package provides a JavaScript API for interacting with PM2, a popular process manager for Node.js applications. This package allows developers to programmatically manage their Node.js processes, including starting, stopping, and monitoring applications, directly from their code.

What are @pm2/js-api's main functionalities?

Managing Processes

This code sample demonstrates how to start a new process (e.g., a Node.js application) using the @pm2/js-api package. It connects to the PM2 daemon, starts a new process with the specified script, and logs the process ID.

const pm2 = require('@pm2/js-api');

pm2.connect().then(() => {
  return pm2.start({
    script: 'app.js',
  });
}).then(proc => {
  console.log(`Application started: ${proc.pm_id}`);
}).catch(err => {
  console.error('Error starting application:', err);
});

Listing Processes

This example shows how to list all processes currently managed by PM2. It connects to PM2 and retrieves a list of all running processes, displaying their details.

const pm2 = require('@pm2/js-api');

pm2.connect().then(() => {
  return pm2.list();
}).then(processes => {
  console.log('Running processes:', processes);
}).catch(err => {
  console.error('Error listing processes:', err);
});

Monitoring Processes

This code snippet illustrates how to monitor PM2-managed processes for messages. It connects to PM2, launches the PM2 bus, and listens for 'process:msg' events, logging any messages received from the processes.

const pm2 = require('@pm2/js-api');

pm2.connect().then(() => {
  return pm2.launchBus();
}).then(bus => {
  bus.on('process:msg', packet => {
    console.log('Process message:', packet);
  });
}).catch(err => {
  console.error('Error launching PM2 bus:', err);
});

Other packages similar to @pm2/js-api

Keywords

FAQs

Package last updated on 20 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc