Setup Guide: Raspberry Pi | Auto start server using pm2 (OPTIONAL)
pm2 is a application that manages other applications, doing things like starting those other applications automatically, restarting them if they crash, etc. pm2 itself uses the node.js JavaScript framework - the same framework that CNCjs uses. pm2 can be used to automatically start the CNCjs server, but there is another way to do it (cron) that is smaller, faster, and simpler. cron is included by default in the Rasbian Linux distribution, so there is no need to download/install any new packages. It is faster because it is written directly in C and thus does not incur the extra overhead of starting node.js and loading a lot of JavaScript code (also, cron is a standard part of Linux startup so it is already running anyway, long before the system is ready for CNCjs startup). It is simpler because you only have to add one line to a file, instead of learning several pm2 commands.
For those reasons, cron is the recommended way to auto-start the CNCjs server on a Raspberry Pi.
That said, if you prefer to use pm2 to start the CNCjs server, here is how.
Install Production Process Manager [PM2]
# Install PM2
sudo npm install -g pm2
# Setup PM2 Startup Script
# sudo pm2 startup # To Start PM2 as root
pm2 startup # To start PM2 as pi / current user
#[PM2] You have to run this command as root. Execute the following command:
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u pi --hp /home/pi
# Start CNCjs (on port 8000, /w Tinyweb mount point) with PM2
pm2 start $(which cncjs) -- --port 8000 -m /tinyweb:/home/pi/tinyweb
# Set current running apps to startup
pm2 save
# Get list of PM2 processes
pm2 list
Join CNCjs Users Group on Facebook to share your experiences with other people.
Site: https://cnc.js.org
- Introduction
- Installation
- Using Pendants
-
Raspberry Pi Setup Guide
- System Setup & Preparation
- Install Node.js & CNCjs
- Install Node.js via Package Manager (Recommended)
- Install Node.js via Node Version Manager (NVM) (Alternative)
- Install Node.js Manually (Alternative)
- Use PM2 to auto-start CNCjs (Optional)
- Use Port 80 (Optional)
- Maintain
- Additional Setup Options:
- CNCjs UI on Pi - Adventures in PiLand
- Pi with Arduino Due
- Electron App
- User Guide
- Tool Change
- Troubleshooting
-
FAQ
- Forgot your password?
- How can I enable WebGL in my browser?
- Raspberry Pi: Error opening serial port "ttyAMA0"
- Webcam Streaming with Raspberry Pi
- Restream RTSP to M-JPEG
- Connect to an Arduino using WiFi
- Install Native Addons with Node.js v4
- Install Serialport on OS X El Capitan
- Kernel panic issue on macOS Sierra for devices using the CH340G, CH34G or CH34X chipset
- Testing without Arduino board
- Development
- API
- Wiki History
- Resources
- About