Get "PHP 8 in a Nuthshell" (Now comes with PHP 8.3)
Amit Merchant

Amit Merchant

A blog on PHP, JavaScript, and more

Expose local directories to network devices in Node.js

Many times, you might stumble upon a situation where you need to expose your local directories to all the network devices.

For instance, you might want to share a folder with your friends or colleagues on the same network so that they can access it from their devices.

I recently came across a pretty handy-dandy way to do this using Node.js. So, there’s this npm package called directory-serve which lets you do exactly that. It’s a simple Node.js package that exposes a local directory to all the network devices.

The directory-serve package

First, install the directory-serve package as a global package.

$ npm i -g directory-serve

Or you can directly use it using npx.

$ npx directory-serve .

Here, by specifying the . (dot), you’re telling the directory-serve to expose the current directory to all the network devices.

Or you can also specify the directory path as the first argument.

$ npx directory-serve /path/to/directory

Accessing the directory

Once you run the above command, the package will start a server on port 8989 (or any other available port) and expose the directory to all the network devices.

directory-serve terminal output

Opening the above URL in the browser will show you the directory listing like so.

directory listing

From this interface, you can access the files and folders of the specified directory. You can also download the files by clicking on the download icon. It’s even possible to upload files to the directory.

Requirements and limitations

The directory-serve package requires Node.js version 14 or above to run. Also, the files and folders in the directory should be accessible by the devices on the same network.

Like this article? Consider leaving a


👋 Hi there! I'm Amit. I write articles about all things web development. You can become a sponsor on my blog to help me continue my writing journey and get your brand in front of thousands of eyes.