Skip to content

A handy study of basic HTML servers functionality using HTML, CSS, JavaScript, Node.js, and NPM to make a basic website with multiple pages.

Notifications You must be signed in to change notification settings

john-azzaro/Study-Node-Web-Servers

Repository files navigation

Node Web Servers Study


What is Node Web Servers Study?

Node Web Servers Study is a study in the construction of a basic web server WITHOUT frameworks like express. Suffice to say that implementing express applications is MUCH easier, however taking a little bit of time to study web servers without express provides a great deal of insight into what happens underneath the hood and try to understand the system a little bit more. If you would like to see the express study of this particular project, please take a look.

Here are a few questions examined in this study:


How do you install the Web Servers Study?

  1. After cloning this repo, run npm install at the command line.
  2. To stat the app, run node index.js at the command line.
  3. Visit http://localhost:3000 to see the study live.

What are the key takeaways from the Node Web Servers Study?


The http module is the foundation of a server without a framework.


In order to allow client-server communication via HTTP protocol, you need to use the built-in http module. This module provides the interface to create either an HTTP server of HTTP client that can communicate with other clients or servers. Additionally, it should be noted that the http module is a streaming interface.

    cosnt http = require('HTTP')

Mimetypes set the type of files you want to serve.


When a request is made for a particular file on your server, the Mimetype essentially instructs your browser as to how it should be handled. In the case of this study, the Mimetype for the html page to interpret all the files with the html extension to interpret those as HTML document files.

    const mimeTypes = { 
    "html": "text/html",                                         // serve html...
    "js": "text/javascript",                                     // ... and javascript files 
    "css": "text/css",                                           // ... and css files         
    "jpeg": "image/jpeg",                                        // ... and jpeg images
    "jpg": "image/jpg",                                          // ... and jpg images
    "png": "image/png",                                          // ... and png images
    }  

Raw Node web servers are complex, but doable!


Express would take the overall win vs raw HTTP Node.js when it comes to creating a http server. Not only does express provide an abstraction layer above the raw http module making it much easier to work with, the benefits of having a wide variety of middleware, etc. vs. raw HTTP Node.js make the process much more simplified and streamlined when developing an app. Also, express has a less"spaghetti"-esque code structure in comparison to express.

To illustrate the type of complexity complexity im refering to, I created two basic servers with a GET route. Both servers do the same thing (i.e. send a response "Hello world!").

"Hello world!" using HTTP server with Node.js:

    const http = require('http');

    http.createServer(function(request, response) {      
        res.writeHead(200, {'Content-Type': 'text/plain'});   
        res.write('Hello world!');
        res.end();
    }).listen(3000);
    console.log("Your app is listening on Port 3000...");

"Hello world!" using express:

    const express = require('express');
    const app = express();

    app.get('/', function(req, res){
        res.send("Hello world!");
    });

    app.listen(3000, function(){
        console.log(`Your app is listening on Port 3000...`);
    });

Does the Node Web Servers Study feature commentary?

Yes! I use extensive Commentary (mostly in the form of my thought process) so that the new and curious can follow the logic in the program and get an idea of my reasoning behind each and every line of code. In addition to my line-by-line commantary, I also provide a Process text file that gives a good outline of my design and implementation process.


What are the key features of the Node Web Servers Study?

Since this study is ongoing, basic functionalities are covered first and more advanced features are added or will be added in the future. I divided this particular study into different branches covering different aspects of basic node servers, which i list below:

Features: Feature Notes:
basic web server see nodeWebServer branch
basic web server with pages see nodeHttpWebServer branch
Web server with fully functioning site see basicServerSite branch

Screenshots

wss-home wss-discover wss-services wss-contact

About

A handy study of basic HTML servers functionality using HTML, CSS, JavaScript, Node.js, and NPM to make a basic website with multiple pages.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published