Node static file server without writing code

Generally, during the front-end development, we require the Web server to run our code and we eventually end up using Apache or Nginx etc. If you use Nodejs or Nodejs environment (Using gulp, grunt or mocha which runs on Node) then there is quick zero configuration package for you that works as HTTP server without writing a single line of code or going through setup.

This is a short post just to provide tips, I hardly do this but this one is worth to share.

Assuming you have Node.js installed in your system. Install the module called ‘http-server’ using the following command.

npm install http-server -g

That’s it. Now you can deliver any static files using this module.

Switch to any folder containing the HTML or static files. Run the Server using the following command.

http-server

Http-server

It will by default load index.html in browser, if present. Point your browser to localhost:8080

Static file serving nodejs

You can change the options such as port etc by providing the parameter.

For more information on parameters, click here.

Shahid
Shahid

Founder of Codeforgeek. Technologist. Published Author. Engineer. Content Creator. Teaching Everything I learn!

Articles: 288