Start a static HTTP web server

Photo by Artem Sapegin on Unsplash

Did you know it’s easy to start an HTTP web server using some of your favorite programming languages?

Prerequisites

Create a directory with an HTML file:

mkdir static
cd static
echo "<h1>Hello, world!</h1>" > index.html

Python

Python 3:

python3 -m http.server

Python 2:

python -m SimpleHTTPServer

View your webpage at localhost:8000. To specify the port, pass the port number in the next argument:

python3 -m http.server 1337
python -m SimpleHTTPServer 1337

Node.js

http-server:

npm install --global http-server
http-server

Or:

npx http-server

View your webpage at localhost:8080. To specify the port, use the -p flag:

http-server -p 1337

Ruby

ruby -run -e httpd .

View your webpage at localhost:8080. To specify the port, use the -p flag:

ruby -run -e httpd . -p 1337

PHP

php -S localhost:8000

View your webpage at localhost:8000. To specify the port, replace the port number in the command:

php -S localhost:1337

--

--

--

remarkablemark.org

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Asset Management is like peas on your plate ….

How Java and C Plus Plus are used in Industry

Using Disposable Password on Bitbucket

Convert OLM files to PST using this advanced app!

Starting out with PostgreSQL

Picking a language for coding interviews

The Rational Product Manager

Beware of ::first-letter when working with Arabic and Farsi

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
remarkablemark

remarkablemark

remarkablemark.org

More from Medium

How to implement a log printing library from 0 to 1

A Few Words on Node.js & An Example of How to Use NPM’s ‘readline-sync’ Package

A Fun, Hacky Way to Handle window.scrollTo

ACOS: Build web games using serverless code, persistent JSON state, and any JS browser framework