Setting up a local web server was something that I haven’t done in a long time and this was really easy. This post shows how to do this with a command line node web server.
Most software that needs a web server sets one up for you. This is pretty easy, and if I have a web app in Visual Studio, it will start up its own server when you run the app. If you had to set your own up, IIS was in many versions of Windows, but it wasn’t a simple thing to configure and manage.
I like simple.
I needed to just serve a file over http to test something. I could have done this by uploading a file to this blog or somewhere else, but I was hoping to keep this small and portable.
As always, I started with Google. I found a bunch of articles on Apache, python (should have tried this) and others. Then I saw this short article on a test web server on Windows. I looked, and this seemed to be something simple. I had node installed, so really I ran this:
npm install -g http-server
This installed somewhere. I had created a new folder in d:\http, but the web server was installed elsewhere. When I typed “http-server” in the command line, it seemed to be running. I saw this:
I created a quick html file, index.html, with this content:
and voila, I had a web server.
It’s basic, but any file I drop into d:\http can be served over http by entering the file name in the path. You can see in the image above, I was testing moving SQL Server backups. That URL actually downloaded that file from my browser.
This showed how you can set up a server with node. It’s quick and easy, and flexible. I can set this up as needed for tests without any big config. If you need this, here’s one way to test your own web stuff.