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

koa-static

Package Overview
Dependencies
Maintainers
8
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-static

Static file serving middleware for koa

  • 1.4.8
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
836K
increased by5.1%
Maintainers
8
Weekly downloads
 
Created

What is koa-static?

The koa-static package is a middleware for Koa, a popular Node.js web framework. It serves static files such as HTML, CSS, JavaScript, and images from a specified directory. This is useful for serving front-end assets in a web application.

What are koa-static's main functionalities?

Serve Static Files

This feature allows you to serve static files from a specified directory. In this example, files from the 'public' directory will be served.

const Koa = require('koa');
const serve = require('koa-static');
const app = new Koa();

// Serve files from the 'public' directory
app.use(serve('./public'));

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

Custom Options

This feature allows you to customize the behavior of the static file serving. You can set options like cache duration, serving hidden files, and specifying a default file.

const Koa = require('koa');
const serve = require('koa-static');
const app = new Koa();

// Serve files from the 'public' directory with custom options
app.use(serve('./public', {
  maxage: 86400000, // Cache files for 1 day
  hidden: true, // Allow hidden files to be served
  index: 'index.html' // Default file to serve
}));

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

Other packages similar to koa-static

Keywords

FAQs

Package last updated on 17 Dec 2014

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