visit
nohup nodemon index.js </dev/null &
npm i -g nodemon
Let me explain in more detail. The “nodemon” is the part of the command that actually runs the script while also automatically restarting it upon any updates. The “nohup” part makes the script keep running even if you exit your VM or kill your terminal.
Something that a lot of people may not know is that you can use nodemon with Python just like with NodeJS! All you need to do is add the --exec python3
argument.
nohup nodemon --exec python3 main.py </dev/null &
In case you’re worried that you won’t be able to stop a continuous processes later, don’t worry, all you have to do is run ps aux
and after getting a table similar to the below…
…get the PID of your nodemon process (223005 in this case) and run sudo kill 223005
.
By running
ps aux
you can also check if your processes are still running.
Now if you want to redirect your scripts’ output to an output file instead of the default nohup.out
file to avoid mixing outputs from multiple scripts, you can specify your output file between your script name and the “</dev/null” parameter using a “>” like this:
nohup nodemon index.js > output.txt </dev/null &
nohup nodemon --exec python3 main.py > output.txt </dev/null &