Saturday, 15 October 2016

How to serve static files with node.js

In front end development to serve static files such as images, CSS files, and JavaScript files you require the web servers. and you need a server like apache or nginx servers to server files.Installing http server and configuration is much hactic for a frontend developers.With the help of node.js we can easily create a http web server.if you are using node.js environment then there is quick configuration package for HTTP server without writing a single line of code.


Assuming you have Node.js installed in your machine.If node.js not installed please read this article Getting started with node.js. You need to install the module called http-server using the following command.

npm install -g http-server

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

~/Desktop mkdir assets && cd $_
~/Desktop/assets http-server

Now assets folder will act like root of the Http server.Please feel free to comment below for suggestions and problems.

Featured post

How to create dynamic schema in mongodb

Sometime what we need in our application is to create mongodb schema for collection and some of our collection schema are same but names are...

Popular Posts