How to auto-restart bottle server when Python file changes using nodemon

Assuming you have a Python script server.py that you want to auto-reload every time the file changes, use the following script using nodemon:

nodemon_start.sh
nodemon -w . --exec python server.py
nodemon_start.sh
nodemon -w . --exec python server.py

The -w . tells  nodemon files to watch for changes of all files in the current directory (.)

I generally recommend creating a script start.sh to automatically run this command:

example.sh
#!/bin/sh
nodemon -w . --exec python server.py
start.sh
#!/bin/sh
nodemon -w . --exec python server.py

and then make it executable using

example.sh
chmod a+x start.sh
chmod_start.sh
chmod a+x start.sh

Now you can run it using

example.sh
./start.sh
run_start.sh
./start.sh

 


Check out similar posts by category: Python