Quickly Serve a Local Directory
When working on HTML files some things won't work if they're just opened from the local hard-drive. The solution is to present them to your browser through some kind of webserver. Setting up a proper webserver like nginx or Apache would be overkill here.
But if Python is available in your environment, everything you need is already there 🤩. This command
python3 -m http.server --bind 127.0.0.1 8000
will serve the current directory on port 8000! Adding --bind 127.0.0.1 makes sure that the server is only available locally.
To wrap this up into a handy command called serve, just add the following code to your .bash_aliases [*].
alias serve='python3 -m http.server --bind 127.0.0.1 8000'
[*] | If you're not using bash I assume you know where to put this 😬. |