Simple NodeJS Web Server

I’m working on a personal project where I need to spin up a simple web server to serve up some deployable assets. In order to get a low overhead server I’m looking into a NodeJS web server.  So I set out to create one. This is the first, and simplest, one I could fine. It gets the job done but I think I probably need something more feature rich. This is as bare bones as it gets.  Let’s dig into this.


"dependencies": {
    "connect": "^3.5.0",
    "serve-static": "^1.11.2"

This web server, outside of Node, only requires two packages: connect and serve-static. Then, I create a server.js file with the following code:

const connect = require('connect'),
      serveStatic = require('serve-static');

const port = '8080';
const location = './dist';

connect().use(serveStatic(location)).listen(port, function() {'Server running on http://localhost:'+port+'...');

In a command prompt that’s navigated to the location where this code is located, type node server.js and it starts the web browser.

This initializes a simple web server at http://localhost:8080 and then loads up anything loaded in the location variable. It works, but doesn’t really have any features other than this. So I’ll be looking for a second version of this, but wanted to share this one as it’s super simple and in a pinch can be used to spin up the most basic of web servers.

Pin It

You must be logged in to post a comment.