Run web server from any folder

A common requirement is to start a web server from a specific folder in the system.

You definitely don't have time to configure a proper web server (such as Apache or Nginx), because this only takes a few minutes or is used to test your application.

how did you do it?

Depending on your preferred language, you may already have everything you need.

If you useNode.jsAnd you have installednpmAlready ran away

npm install -g http-server

Then runhttp-serverIn the folder you want to make public through the server.

By default, it will start the server on port 8080, but you can use-pMark (see more options by runninghttp-server --help).

If you use Python and have it installed, you just need to run

python -m SimpleHTTPServer 8080

(Python 2)


python -m http.server 8080

(Python 3)

to start a local server on port 8080.

If you use PHP and run a modern version of it, run

php -S localhost:8080

Download mine for freeNode.js manual

More node tutorials: