This page looks best with JavaScript enabled

Spin-up a quick web server in Javascript

 ·   ·  ☕ 2 min read

Use these two quick ways to get a webserver up and running from any folder.

1. Use http-server

Install http-server.

1
npm install http-server -g

Navigate to any folder where you need a quick web server and start server.

1
2
cd client/dist
http-server

You can even proxy requests to a back-end server where required.

1
http-server -P localhost:3333

The above command will start a server at port 8080, and any requests to back-end (e.g /api) is proxied to localhost:3333 if the same is not resolved.

2. Use a full-fledged NGINX or Apache server

Configure a standard web server on the system to a specific folder. You could get your build script to copy over generated files to that folder, or manually copy contents to the folder.

You could also link the build folder (e.g. dist in Vue) to something accessible by the web server.

You have access to the complete power of a web server with this setup. You can setup proxies, see access and error logs, play around with security certificates, etc. This is especially useful if you are replicating a full clone of production or staging environments for development.

I use Laragon for the purpose.

Laragon provides a central console to manage Apache / Nginx web server, and databases (Postgres, MySQL or something else altogether). Laragon is quite easy to configure, light-weight, and can easily work with different versions of databases without any fuss.

Stay in touch!
Share on

Prashanth Krishnamurthy
WRITTEN BY
Prashanth Krishnamurthy
Technologist | Creator of Things