How To Setup Static File Server Instantly

server -setup static file server

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 turn your system into a static file server, allowing you to serve your files over network. You can access the files from any devices regardless of their operating system. All you need is a web browser. This utility also can 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 http://192.168.43.192:5000 in the browser’s address bar. Replace 192.168.43.192 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 it’s 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!

Cheers!

Resource:

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You may also like...

2 Responses

  1. Rick Stanley says:

    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)
    https://www.digitalocean.com/community/tutorials/how-to-configure-ssh-key-based-authentication-on-a-linux-server

    To secure ssh even more:

    https://www.cyberciti.biz/tips/linux-unix-bsd-openssh-server-best-practices.html
    https://linux-audit.com/audit-and-harden-your-ssh-configuration/

    and others.

  2. Jay Woods says:

    [[email protected] ~]$ serve Documents/
    /usr/lib/node_modules/serve/bin/serve.js:83
    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] ~]$

    What?

Leave a Reply

Your email address will not be published. Required fields are marked *

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