Code Monkey home page Code Monkey logo

pm2-ws's Introduction

pm2-ws

A WebSocket server for working with PM2

Installation & usage

NPM

Install it globally:

  • Install it: yarn global add pm2-ws or npm i -g pm2-ws
  • Use it: pm2-ws

Install it in your project:

  • Install it: yarn add --dev pm2-ws or npm i --save-dev pm2-ws
  • Add it to your PM2 startup script, so it's always active when PM2 is active.

Once set up and running, you can connect to the WebSocket server:

let socket = new WebSocket("ws://localhost:7821");
socket.onmessage = (message) => {
  console.log(JSON.parse(message.data));
};

This socket will only send stringified JSON, so you should be able to JSON.parse anything incoming.

Options

Use environment variables to configure how the script runs.

HOST

The host you'd like the WebSocket served on.

Default: localhost

PORT

The port you'd like the WebSocket served on.

Default: 7821

CLEAR

Clear the terminal when you start the script. Just to be that annoying script. Set to false to disable.

Default: unset (enabled)

PROCESS_PING_INTERVAL

Milliseconds between each Process Ping (a websocket event that transmits the status of processes). Set to 0 to disable entirely, even when Commands.StartProcessPings is called.

Default: 5000

Sending commands

Once open, the socket can receive commands to execute PM2 functions. They need to be delivered in a JSON-stringified object with the command specified under the command key and remaining properties as arguments.

socket.send(
  JSON.stringify({
    command: "StartProcess",
    name: "auth-server",
  })
);

Commands

Any command you can send (and event you can receive) is enum'd, so for the most up to date list refer to the code. Here's a brief description of what they do and need as arguments:

GetProcesses

Retrieves list of PM2 processes.

StartLogs

Start streaming process logs. Depending on your active processes this can be a lot of data.

StopLogs

Stop streaming process logs.

StartProcess

Starts a stopped process. Requires name as an argument.

StopProcess

Stops a started process. Requires name as an argument.

RestartProcess

Restarts any process. Requires name as an argument.

License

MPL-2.0

pm2-ws's People

Contributors

jodyheavener avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.