Sunday, 21 January 2018

Node.js application in production (with restart)


Node.js applications can be managed and restarted upon a rebooted with PM2, which is a process manager for Node.js applications.



To install the Node.jsmodule:
sudo npm install -g pm2
To start and daemonize any application:
pm2 start application.js

Then to generate an automatically-configured startup script for your machine
pm2 startup
pm2 startup upstart
[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 upstart -u ...
Copy and paste the command.

Once you have started all the Node.js applications you want to manage across server restarts or reboots.


pm2 save
and to remove it from startup
pm2 unstartup

Same needs to be done after npm update or upgrade (unstartup then startup)

Init systems

  • systemd: Ubuntu >= 16, CentOS >= 7, Arch, Debian >= 7
  • upstart: Ubuntu <= 14
  • launchd: Darwin, MacOSx
  • openrc: Gentoo Linux, Arch Linux
  • rcd: FreeBSD
  • systemv: Centos 6, Amazon Linux


Tuesday, 16 January 2018

Linux bash to find files and exlude permission denied

So this is another of those "post to self" notes.
Lots of times you need to search for a file or directory under a user account and get this long list of "Permission Denied" entries back.

The below find command will exclude those.

Terminal command to find a directory with name image: 
find / -name image -type d 2>&1 | grep -v "Permission denied"