/

Running a Web Server from Any Folder

Running a Web Server from Any Folder

Running a web server from a specific folder on your system can be a common requirement. However, configuring a full-fledged web server like Apache or Nginx might not be practical for quick testing or temporary use. Fortunately, depending on your preferred programming language, you may already have the necessary tools at your disposal.

Node.js Approach

If you use Node.js and have already installed npm, you can easily accomplish this task. Start by running the following command:

1
npm install -g http-server

Next, navigate to the folder you want to expose through your server and run the command:

1
http-server

By default, the server will start on port 8080. If you wish to use a different port, you can specify it using the -p flag. For more options, you can run http-server --help.

Python Approach

For Python users, running a local server on a specific folder is straightforward. If you have Python installed, follow these steps:

Python 2

1
python -m SimpleHTTPServer 8080

Python 3

1
python -m http.server 8080

Both commands will start a local server on port 8080.

PHP Approach

If you use PHP and have a recent version installed, running a server on a specific folder is simple. Execute the following command:

1
php -S localhost:8080

By default, the PHP server will start on port 8080.

These methods allow you to quickly spin up a web server from any folder, providing a convenient way to test your applications or serve temporary content.

tags: [“web server”, “Node.js”, “Python”, “PHP”, “testing”]