DEV Community

loading...

3 Different ways to start a HTTP Web Server from the Terminal

Benjamin Kadel
Programmer (Android Developer at the moment), Tech Evangelist, Speaker, Educator, YouTuber
・2 min read

In this relatively quick video I want to showcase 3 very quick and different ways that you can start up a HTTP Web Server from the terminal on your local machine, in a specified folder, so that you can serve content to other machines on your network or simply to yourself. This is incredibly useful to web devs in particular so that can rapidly set up a dev server to develop and test on...

The 3 different methods use:

  • PHP
  • Python
  • NodeJs

Full Video with the information (or scroll down to read...)

For those of you who prefer to read then let me simply show you the commands...

PHP
PHP has an in-built web server that you can trigger like this:

php -S 0.0.0.0:8080

(for more information please visit this link: https://www.php.net/manual/en/features.commandline.webserver.php)

Python (Version 3)
Python too has an in-built web server that you can trigger like this:

python -m http.server 8080

(for more information please visit this link: https://docs.python.org/3/library/http.server.html)

NodeJS
Node has a package called "http-server" that needs to be installed before you can use this command, this can be done with this command:

npm install http-server -g

This installs the package globally on your machine (-g) so that you can use it where ever you like throughout your system, then the command to actually launch the server is this:

http-server -p 8080

(for more information please visit this link: https://www.npmjs.com/package/http-server)

Outro
Of course with all these commands you can change the port number (8080 in every example) to a port number of your choice and then once you have run each of these commands you can then go to your browser and go to the address:
localhost:8080 OR 127.0.0.1:8080
to communicate with your web server and the content that is located within the folder that you triggered the command from, it is also accessible to any other device on your network that wants to access your web server, so keep that in mind!
...

I am trying to grow my new YouTube channel too...

cough
Link: https://www.youtube.com/channel/UCMz9lmndR0BEqi70kM_ioyA
cough

So please give me as much feedback & criticism as possible so that I can improve and if you liked it or any other video that I have done please share it around, it would really help!

For any questions about anything you have seen here or in any of my other videos or even if you have ideas for future videos, please reach out on twitter https://twitter.com/ben_kadel

Thanks!

Discussion (0)