Image for post
Image for post
Photo by Ferenc Almasi on Unsplash

Lately, I am learning to write more and more of my JavaScript code without the help of any library or framework. I like to have a good unit test coverage for any code I write because that gives me confidence whenever I want to refactor my code or change it for any other reason. In this blog post, I have demonstrated how I went about writing unit tests without any framework.

We will start by creating two files:

  • test.js contains the test functions assert and it that we need for testing. It also contains all the unit tests.
  • test.html is the test runner. …


Image for post
Image for post
Photo by Agence Olloweb on Unsplash

This article describes how to search an array of JSON objects for given keywords and display the result on a web page.

We will search a list of books. Each book object contains a title, subtitle, author, category and publisher. We want to be able to search all the fields for a set of search terms and display the result on the web page.

We will start with displaying a list of books on the webpage.

The render() function takes an array of JSON objects as its parameter. …


Image for post
Image for post

In the previous post, I demonstrated how to write a minimal http server in Node.js without using any framework to serve static content. In this post, I have enhanced the code to serve dynamic content as well.

Why?

  • Why not?
  • Express, though it claims to be un-opinionated — is opinionated.
  • I wanted to write a simple server whose job is to just serve the content and let the handler(s) decide what to do with the content.

The Code

Here’s the complete code for the server.
Place this code in./minimal-dynamic-http-server/index.js

// Dependencies
const http = require('http');
const path = require('path');
const fs = require('fs');
const url =…


Minimal HTTP Server in Node.js
Minimal HTTP Server in Node.js
Photo by Markus Spiske on Unsplash

Update: Check out my NodeJS Server without Express article if you are interested in serving static as well as dynamic content.

Following is the code for the HTTP server written in Node.js without using any framework.

// Dependencies
const http = require('http');
const url = require('url');
const fs = require('fs');
const path = require('path');
// Container Object
const server = {};
// Base Directory - Assuming minimal-http-server
// will be accessed from its own folder.
const baseDir = path.join(__dirname, '../');
// Create a server
const httpServer = http.createServer((request, response) => {

const parsedUrl = url.parse(request.url, true);
let pathName = parsedUrl.pathname; …


Image for post
Image for post
Photo by Max Chen on Unsplash

Last month I re-designed my personal website where I listed all the recent projects I worked on. The HTML code looked something like this

<div class="project-cards-grid">
<div>
<h1>Project 1</h1>
<h2>Client 1</h2>
<div class="summary">Lorem ipsum</div>
<div class="technologystack">
<ul>
<li>NodeJS</li>
<li>AngularJS</li>
<li>Bootstrap</li>
</ul>
</div>
</div>
<div>
<h1>Project 2</h1>
<h2>Client 2</h2>
<div class="summary">Lorem ipsum</div>
<div class="technologystack">
<ul>
<li>NodeJS</li>
<li>AngularJS</li>
<li>Bootstrap</li>
</ul>
</div>
</div>
<div>
<h1>Project 3</h1>
<h2>Client 3</h2>
<div class="summary">Lorem ipsum</div>
<div class="technologystack">
<ul>
<li>NodeJS</li>
<li>AngularJS</li>
<li>Bootstrap</li>
</ul>
</div>
</div>…

About

Amit Gupta

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store