Poor man's Live Reload
After Googling, I found a wonderful tool named LiveReload which does exactly what I need and some more. But it costs money. So, I thought, can I make it on my own? Well, I did some quackery and this is the result. It reloads Html file in browser automatically when source/target file is changed.
Node.js v17.0.1 npm v8.1.0
git clone https://github.com/asiftyro/pmlr.git cd full/path/to/pmlr/dir npm i
Add following two lines inside
<head>...</head> of target Html file:
<script src="http://localhost:3000/socketiojs"></script> <script src="http://localhost:3000/pmlr"></script>
To run the auto reloader:
cd full/path/to/pmlr/dir node app.js full/path/of/target/file/to/watch
Now open the Html file in browser. Change code in the target file and save. Html file in browser should reload/refresh automatically. To stop, press
Ctrl+C in terminal.
NodeJS v17.0.1 Socket.IO v4.3.2 macOS Monterey 12.0.1
macOS Monterey 12.0.1 Google Chrome 96.0.4664.55
Tested by rkbi on:
ArchLinux 5.15.5-arch1-1 Firefox 94