How to set up Node server

Setting up a local Node server is a quick and easy process. First, we need to have Node.js installed. It’s available from

Let’s set up the server. First, we’ll need to install the server package and then we will use it to serve our files. We’ll accomplish this on a command line.

1. Let’s go to our project directory `cd ./our_project`
2. We need to install the http-server using the package manager. We can do it with just this one command: `npm install http-server -g`

The installation created node_modules directory in our current directory and downloaded the http-server package to that directory. The -g option installs the package globally so it can be used as a command line tool. After these super easy steps we are ready to start the server.

3. `http-server ./my_project/public` starts serving the files from ./my_project/public.

We can visit our server using url http://localhost:8080.

Some http-server options

The default port http-server uses is 8080. We can change it with a -p switch. There are also other options to configure the server, but typically they are not needed for development or testing purposes.