Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

serve-index

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

serve-index

Serve directory listings

  • 1.9.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is serve-index?

The serve-index npm package is a middleware for Node.js that serves pages that display directory listings. It's commonly used with Express or other middleware-based HTTP server frameworks. It provides a responsive web interface to navigate the file structure of the served directories.

What are serve-index's main functionalities?

Directory Listing

This feature allows you to list the contents of a directory in a web page. The code sample shows how to use serveIndex with Express to serve the contents of the 'public/files' directory with file icons.

const express = require('express');
const serveIndex = require('serve-index');

const app = express();

app.use('/files', express.static('public/files'));
app.use('/files', serveIndex('public/files', {'icons': true}));

app.listen(3000);

Custom Styles and Templates

Serve-index allows for customization of the directory listing by using custom templates and styles. The code sample demonstrates how to specify a custom HTML template for the directory listing.

const express = require('express');
const serveIndex = require('serve-index');

const app = express();

app.use('/files', serveIndex('public/files', {
  'icons': true,
  'template': 'path/to/custom/template.html'
}));

app.listen(3000);

Filtering Files

Serve-index can filter the files that are displayed in the directory listing. In the code sample, a filter function is used to display only files with the '.html' extension.

const express = require('express');
const serveIndex = require('serve-index');

const app = express();

app.use('/files', serveIndex('public/files', {
  'filter': function (filename, index, files, dir) {
    return filename.endsWith('.html');
  }
}));

app.listen(3000);

Other packages similar to serve-index

FAQs

Package last updated on 29 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc