Day 98: Learning How Buffers Work

In trying to use a stream in Node.js with understanding what is happening under the hood I started to look into buffers. Here is the trick though. The use of hexadecimal number representation is throwing me off a bit and it has me trying to practice my number base conversions LOL. Overall it does not seem to difficult but I just need to put in a bit more time.

Within the context of the project this is not needed. The files I am trying to send back in the HTTP responses are really small basic HTML files. But in the future I want to send larger files and before I use a library like Express which will likely abstract processes I want to understand how to send files using streams and how streams use buffers (I think I got that right… LOL).

I definitely have a lot of work out there for me but hopefully taking the time to understand the basics underneath the hood will help when I get to more advanced topics.

TLDR;

Okay, so here are the highlights of what I did:

  • Back-end Dev -> Started reading an article on Buffers in Node.js. I haven’t finished it yet because I am also watching a few videos on the topic as well. There is an adjustment for sure in trying to understand how things work.
  • Node.js -> Read through some of the API docs on the http.ServerResponse class in Node.js. I still need to read more about the fs module and the http.ClientRequest classes. I got a decent understanding of how to use the ServerResponse objects in server callback functions. I’m slowly getting more comfortable with what is going on LOL.
  • Practice -> Continued working on the Basic Informational Site project. I did not do much besides reference my working code with the docs to compare and see if I am doing things correctly.

Server Code so far:

// Basic Information Site (Server)

const http = require("http");
const fs = require("fs");
const port = process.env.PORT || 8080;

const server = http.createServer((req, res) => {
  /*
   * What is needed:
   * - clean request url to determine which file to send
   * - Set the Correct headers to send an html file as a response to the HTTP request
   * - Use the fs module to get the file and send it back to the client
   *
   */
  res.statusCode = 200;
  res.setHeader("Content-Type", "text/html");
  res.end("<h1>Hello World</h1>");
});

server.listen(port, "localhost", () => {
  console.log("Connection made");
});


Goal For Round 7 of the #100DaysofCode Challenge

This is my seventh round of the “#100daysofcode” challenge. I will be continuing my work from round five and round six into round seven. I am currently working through the book “Cracking the Coding Interview” by Gayle Laakmann McDowell. My goal is to become more familiar with algorithms and data structures. This goal was derived from my goal to better understand operating systems and key programs that I use in the terminal regularly e.g. Git. This goal was in turn derived from my desire to better understand the fundamental tools used for coding outside of popular GUIs. This in turn was derived from my desire to be a better back-end developer.

I have no idea if my path is correct but I am walking down this road anyways. Worst case scenario I learn a whole bunch of stuff that will help me out on my own personal projects.