There are 2 ways to create instant web server by command line –
1 – http-server – Its installation is done by the npm. You need to install node on your system.
Run the following command, once you have npm. -g make http-server available globally:
npm install http-server -g
Go to static folder where you wish to create local server and run command line with the following command –
It will show the message –
Starting up http-server, serving ./ on port:8080
Hit Ctrl-C to stop the server.
The default port used by http-server is 8080, but you can change this, and a few other options, via command line switches:
- -p to specify which port to listen on
- -a to tell it which IP address to bind to
- -i to configure whether to display autoIndex (defaults to true)
- -s or –silent to turn off console logging
- -h or –help to display this list of available commands
2- Python SimpleHTTPServer module – To start an instant web serve in the directory by command line use the follwing command –
python -m SimpleHTTPServer
This will publish the current directory on server, we can access it on port 8000, it is default port for python server. We can access it by our ip x.x.x.x.:8000 or 127.0.0.1:8000 etc.
Note- Python should be installed on system to use this feature.