Home Command line utilities How To Instantly Setup Static File Server In Linux
serve -setup static file server

How To Instantly Setup Static File Server In Linux

By sk

Ever wanted to share your files or project over network, but don't know how to do? No worries! Here is a simple utility named "Serve" to share your files instantly over network. This simple utility will instantly setup static file server in Linux operating system and allow you to serve your files over local area network. You can access the files from any devices regardless of their operating system. All you need is a web browser. This utility can also be used to serve static websites. It is formerly known as "list" and "micro-list", but now the name has been changed to "serve", which is much more suitable for the purpose of this utility.

Setup Static File Server Using Serve

To install "serve", you need to install NodeJS and NPM first. Refer the following link to install NodeJS and NPM in your Linux box.

Once NodeJS and NPM installed, run the following command to install "serve".

$ npm install -g serve

Done! Now is the time to serve the files or folders.

The typical syntax to use "serve" is:

$ serve [options] <path-to-files-or-folders>

Serve Specific files or folders

For example, let us share the contents of the Documents directory. To do so, run:

$ serve Documents/

Sample output would be:

As you can see in the above screenshot, the contents of the given directory have been served over network via two URLs.

To access the contents from the local system itself, all you have to do is open your web browser and navigate to http://localhost:5000/ URL.

The Serve utility displays the contents of the given directory in a simple layout. You can download (right click on the files and choose "Save link as..") or just view them in the browser.

If you want to open local address automatically in the browser, use -o flag.

$ serve -o Documents/

Once you run the above command, The Serve utility will open your web browser automatically and display the contents of the shared item.

Similarly, to access the shared directory from a remote system over network, type in the browser's address bar. Replace with your system's IP.

Serve contents via different port

As you may noticed, the serve utility uses port 5000 by default. So, make sure the port 5000 is allowed in your firewall or router. If it is blocked for some reason, you can serve the contents using different port using -p flag.

$ serve -p 1234 Documents/

The above command will serve the contents of Documents directory via port 1234.

To serve a file, instead of a folder, just give its full path like below.

$ serve Documents/Papers/notes.txt

The contents of the shared directory can be accessed by any user on the network as long as they know the path.

Serve the entire $HOME directory

Open your Terminal and type:

$ serve

This will share the contents of your entire $HOME directory over network.

To stop the sharing, press CTRL+C.

Serve selective files or folders

You may not want to share all files or directories, but only a few in a directory. You can do this by excluding the files or directories using -i flag.

$ serve -i Downloads/

The above command will serve entire file system except Downloads directory.

Serve contents only on localhost

Sometimes, you want to serve the contents only on the local system itself, not on the entire network. To do so, use -l flag as shown below:

$ serve -l Documents/

This command will serve the Documents directory only on localhost.

This can be useful when you're working on a shared server. All users in the in the system can access the share, but not the remote users.

Serve content using SSL

Since we serve the contents over the local network, we need not to use SSL. However, Serve utility has the ability to shares contents using SSL using --ssl flag.

$ serve --ssl Documents/

To access the shares via web browser use "https://localhost:5000" or "https://ip:5000".

Serve contents with authentication

In all above examples, we served the contents without any authentication. So anyone on the network can access them without any authentication. You might feel some contents should be accessed with username and password.

To do so, use:

$ SERVE_USER=ostechnix SERVE_PASSWORD=123456 serve --auth

Now the users need to enter the username (i.e ostechnix in our case) and password (123456) to access the shares.

The Serve utility has some other features, such as disable Gzip compression, setup * CORS headers to allow requests from any origin, prevent copy address automatically to clipboard etc. You can read the complete help section by running the following command:

$ serve help

And, that's all for now. Hope this helps. More good stuffs to come. Stay tuned!



Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like


Rick Stanley April 14, 2018 - 8:23 pm

Rather than install NodeJS and NPM, then serve, I would strongly recommend installing SSH server and client. “serve” may, and probably do have security issues.

SSH can be used safely remotely, and locally.

Please see the following sites:

https://www.nixtutor.com/linux/installing-and-configuring-an-ssh-server/ (Many other sites give similar instructions)

To secure ssh even more:


and others.

Jay Woods April 14, 2018 - 9:36 pm

[[email protected] ~]$ serve Documents/
detect(port).then(async open => {

SyntaxError: missing ) after argument list
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:383:7)
at startup (bootstrap_node.js:149:9)
[[email protected] ~]$



Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More