I will highlight two packages you can use to create a static HTTP server on your computer with Node.js.

1. http-server

The http-server is a basic, zero-configuration static HTTP server that can be run from the command line. It has the capability to be used in production, but it is also straightforward and customizable for testing, local development, and educational purposes.

To use this package, please install it globally using the following command:

npm install --global http-server

Navigate to the directory you wish to use as your server root and run the command:

http-server .

For more information about the package, please refer to the documentation here – https://www.npmjs.com/package/http-server

2. serve

serve is designed to assist you in serving a static site, single page application, or a static file, whether it’s on your device or on the local network. Additionally, it offers a clean interface for displaying the contents of the directory.

You can use this package by installing it using the command below:

npm install --global serve

Once that’s done, navigate to the directory you want to use as your server root, and then run the command below:

serve .

For additional information about the package, please visit the documentation here – https://www.npmjs.com/package/serve

Enjoy!!

Tagged in:

,