Create a Server that hosts just HTTP Sites

Shiori Soma
2 min readAug 9, 2021
Photo by Ashwini Chaudhary on Unsplash

1. Create a folder.

2. Create a JS file.

3. Generate package.json

In JS file

There are mainly three methods to be used in JS file.

http

Loading `http` object with `require` method.

const http = require(‘http’);

This code provides functionality for HTTP access.

HTTP is a protocol (procedure) used for exchanging data on websites.

createServer

Create a script to create a server object.

The server object is provided as an object called `http.Server`, and the createServer method is used to create this object.

const server = http.createServer((request, response) => {
Displayed screen
})

- request: from client to server
- response: from server to client

In `createServer`, there is a function that is required when the `http.Server` object created by `createServer` is run as a server. When someone accesses that server, this function will be called.

Listen

--

--

Shiori Soma

I’m a front-end web developer based in Vancouver, studying CICCC, an web and mobile app development course. https://shiory602.github.io/portfolio/