Serving static files with Node JS

During the front-end development to serve static files such as images, CSS files, and JavaScript files you require the web servers. and as of now you used Apache or Nginx etc servers to server files. Installing HTTP servers and configuring the environment with Apache and Nginx …etc bundles is bit difficult for front end developers.

Fortunately with node js front-end developers can easily create http web servers. If you use Nodejs or Nodejs environment then there is quick zero configuration package for you that works as HTTP server without writing a single line of code.

Assuming you have Node.js installed in your machine. You need to install the module called http-server using the following command.

That’s it. Now you can serve any static files and assets using this module. All you have to do is, switch to any folder and run the server using the following command. That folder will act as server and it will serve static files such as images, CSS files, and JavaScript files.

Now demo folder will act like root of the Http server.

Serving static files with Node JS

Serving static files with Node JS

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

Arjun
I am Arjun from Hyderabad (India). I have been working as a software engineer from last 7+ years, and its my passion to learn new things and implement them as a practice. Aside from work, I likes gardening and spending time with pets.