we2
v1.0.27
Published
A process management app for production apps, similar to PM2
Maintainers
Readme
we2 CLI
A process management app for production apps, similar to PM2.
Installation
For Local Development
To install dependencies and make the we2 command available on your system for development, run the following commands from the project's root directory:
npm install # Install local dependencies
npm link # Create a global symlink to your local projectGlobal Installation (from source)
To install the package globally on your system directly from the source code (without publishing to npm), you can run this command from the project's root directory:
npm install -g .Usage
Create a simple server file, e.g., app.js:
require('http').createServer((req, res) => res.end('hello')).listen(3000);Start a process
we2 start app.jsStart with options
we2 start app.js --name myapp --instances max --watch --env productionOptions:
-n, --name <name>: Specify app name-i, --instances <instances>: Number of instances (max for all CPUs)-w, --watch: Watch and restart on file changes--ignore-watch <patterns>: Ignore watch patterns (comma-separated)--max-memory-restart <limit>: Restart if memory exceeds limit (e.g., 200MB)--restart-delay <ms>: Delay between restarts--log <path>: Specify log file--no-autorestart: Disable auto restart--env <env>: Environment (development, production)
List running apps
we2 listShow details
we2 show myappRestart the app
we2 restart myappStop the app
we2 stop myappDelete the app
we2 delete myappTail logs
we2 logs myappMonitor processes
Generate ecosystem file
we2 ecosystemOther commands
we2 flush [name|all]: Flush logswe2 save: Save process listwe2 update: Update we2
Running on System Boot (Production)
To ensure the we2 daemon starts automatically when your server reboots, you need to create a service file for your operating system.
Example for Linux with systemd
Create a service file:
sudo nano /etc/systemd/system/we2-daemon.serviceAdd the following content. Make sure to replace
/path/to/nodeand/full/path/to/your/project/we2_cli/daemon.jswith the actual absolute paths on your system. You can find the path to Node by runningwhich node.[Unit] Description=we2 Process Manager Daemon After=network.target [Service] ExecStart=/path/to/node /full/path/to/your/project/we2_cli/daemon.js Restart=always User=your-username # Replace with the user you want to run the service as Environment=NODE_ENV=production [Install] WantedBy=multi-user.targetEnable and start the service:
sudo systemctl daemon-reload # Reload systemd to recognize the new file sudo systemctl enable we2-daemon # Enable the service to start on boot sudo systemctl start we2-daemon # Start the service immediately sudo systemctl status we2-daemon # Check the status of the service
Other Operating Systems
- macOS: You would use
launchdand create a.plistfile in~/Library/LaunchAgents. - Windows: You can use a tool like
node-windowsto wrap thedaemon.jsscript as a Windows Service.
