In order to develop or test some static code, without copying them into your apache webroot or something else, you easily can start a simple static webserver within the directory you are currently in with following tools.
Because you sometimes you just need a http:// (likely localhost) Url instead of a file://… one.
- If you have Python (https://www.python.org/) installed you can start a static web server with following command, depending on the installed version.
python -m SimpleHTTPServer [port]//python2 python3 -m http.server [port]//python3
- If you have PHP > 5.4.0 (http://php.net/) installed you can start one with:
php -S localhost:[port]
- Using Ruby (https://www.ruby-lang.org/) you setup a simple server with this command:
ruby -run -e httpd . -p [port]
- For node.js (http://nodejs.org/) I use the “simple, zero-configuration command-line http server” package (https://www.npmjs.org/package/http-server).
After the default npm installation
npm install http-server -g
you just type
into your console.
These are some nifty tools (or “oneliners“), when it comes to browse a static/client app/website/file with your browser in your local environment without copying the files somewhere else.