Skip to content

Run a web server from any folder

A common need you can have is to spin up a Web Server from a particular folder in your system.

You have absolutely no time to configure a proper web server like Apache or Nginx because this is just for a few minutes or for testing your app.

How do you do so?

Depending on the language you prefer, you might already have all you need.

If you use Node.js and you have installed npm already, run

npm install -g http-server

and then run http-server in the folder you want to expose through your server.

By default it will start the server on port 8080, but you can change it using the -p flag (see more options by running http-server --help).

If you use Python and have it installed, just run

python -m SimpleHTTPServer 8080

(Python 2)

or

python -m http.server 8080

(Python 3)

to start a local server on port 8080.

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

php -S localhost:8080

→ Get my Node.js Handbook

→ I wrote 17 books to help you become a better developer:

  • C Handbook
  • Command Line Handbook
  • CSS Handbook
  • Express Handbook
  • Git Cheat Sheet
  • Go Handbook
  • HTML Handbook
  • JS Handbook
  • Laravel Handbook
  • Next.js Handbook
  • Node.js Handbook
  • PHP Handbook
  • Python Handbook
  • React Handbook
  • SQL Handbook
  • Svelte Handbook
  • Swift Handbook
...download them all now!

Also, JOIN MY CODING BOOTCAMP, an amazing cohort course that will be a huge step up in your coding career - covering React, Next.js - next edition February 2025

Bootcamp 2025

Join the waiting list