Minimal HTTP Server in Node.js without Framework

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.

Place this code in


then import the server in your code

const server = require('./minimal-http-server');

Start the server as follows:


The server will start on port 3000. Alternatively, you can specify the port as the first argument and hostname as the second argument to the init() method as shown below:

server.init(4000, 'myserver');

After writing this code, I found a similar code on MDN also.

View Source



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