Please note this is NOT how you deploy Node.js apps in real production (e.g. docker, nginx, etc.). The goal is to demo crontab and Node.js. In production, you build docker images and there's no need to use pm2 to serve your app.
1. Make sure your Node.js installation didn't mess up. All your global packages should live under /usr/bin, not /usr/local/bin, or you need to reinstall Node.js
2. sudo npm i -g pm2
pm2 is a package for serving multiple Node.js apps. It balances work loads.
3. create a bash file that launches your Node.js apps
4.1 edit /ect/crontab to execute your bash file at boot or at whatever time you prefer (e.g. weekly). The syntax is
interval user file
4.2 alternatively
sudo crontab -e
create a cron job that is run as super user (root). The file is located at
/var/spool/cron/root
The syntax is [interval] [file]
No need to specify user since the user is root.