DEV Community

Leo Khramtsov
Leo Khramtsov

Posted on

Simplex node.js http server

Introduction

Hello everyone, I've built a simple Node.js Http-Server with router. I wanted to build a server with routing support without using any third party libraries.

Right now it does not support any middleware or request body parsing, it is something i want to explore adding in the future.

Key supported features:

MIME types for most common files
Serves HTML, JS, CSS, plain text and images
Serves index.html as a default directory index
Responds with error codes for missing files
Ability to set route aliases
Ability to set custom routes

Usage

Alt Text

Static assets

Static assets are served from /public directory

/public - HTML files
/public/static
/public/static/css - CSS files
/public/static/images - Images
/public/static/js - Javascript files

Route Aliases

Route aliases can be set in /routes/aliases.js

"/": "/index.html",
"/about": "/about.html",
"/contact": "/contact.html",
"404": "/404.html",

Source Code

You can view source code on GitHub https://github.com/nvrenuff/simplex-http-server.

Feel free to use this for leaning purposes or simple non production projects.

Any feedback, recommendations are welcome :)

Top comments (0)