1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

    Serve a Static HTML Page for Development

    Chris AchardChris Achard
    cssCSS
    htmlHTML 5

    We'll be building www.patio11bot.com from start to finish as a staic HTML document - so the first step is to setup a mini web server, so that we can view the webpage locally.

    There are three easy ways to do that:

    // python 2:

    > python -m SimpleHTTPServer 8000

    // python 3:

    > python -m http.server 8000

    // node:

    > npm install -g http-server

    > http-server

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Discuss

    Discuss

    Transcript

    Transcript

    Instructor: Let's start with a blank text file. We'll paste in a basic HTML document. This Web page, we'll call the "Patio11 Bot" because it's going to give out quotes from Patio11's blog posts. We can save that as index.html.

    If we find that folder on the disk, then we can see the Web page by right-clicking and opening in Chrome. There we go. We can see the content of that page in Chrome. There's no styles yet though. Back in a text editor, let's make a new file called "style.css." We can paste in some styles for that page.

    Back in index.html, we want to use those styles. If we just link the stylesheet like we normally would think to do, then when we refresh the Chrome browser, those styles aren't applied. If we open the console, we can see that Chrome can't fetch the style files because we're not actually serving the Web page. We're just viewing the local file in Chrome.

    Let's head over to the terminal. In the folder with the index.html and style.css files, we can start a mini-web server. The first way we'll do that is with Python. We can call Python and then use -m, which lets Python search the Python module namespace.

    In Python 2.0you can use SimpleHTTPServer and then a port, like 8000. If you have Python 3.0installed, like I do, then instead of SimpleHTTPServer, you can use http.server. Now Python is running a mini-web server in that folder. If we switch back to the browser and go to localhost port 8000, then we get the site.

    If you want an alternative to Python's simple Web server, then we can go back to the terminal and install the Node version from npm with npm install -g httpserver, which will install the httpserver command globally. Then we can just run httpserver. Back in the Web browser, we can visit port 8080 to see the site running.