Easy way to setup a local HTTP Server on macOS
You want to run a simple local HTTP Server on your local PC. You want to test your html
, js
,… files locally.
Here is the easiest way to do it.
1. Using SimpleHTTPServer
Create your test folder, move all your html
, js
files to that folder.
$ mkdir test
$ cd test
Check your python version
$ python --version
If you have Python version 2, run SimpleHTTPServer
using
$ python -m SimpleHTTPServer 1313
If you have Python version 3, using
$ python -m http.server 1313
You will have your local HTTP Server running in port 1313
. Using your Web Browser and access to http://localhost:1313/
2. Using http-server
If you are more familiar with Node.js, http-server
is your choice. If you are new to Node.js, why not give it a try.
Take 1 minute to go to Node.js homepage to download and install it.
Install http-server
using:
$ npm install http-server -g
Go under the folder you want to serve your files and setup your local server by running this command:
$ http-server ./ -p 1313
Now you have your local HTTP Server running in port 1313
. Using your Web Browser and access to http://localhost:1313/