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

koa-send

Package Overview
Dependencies
Maintainers
7
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-send

Transfer static files

  • 1.2.4
  • Source
  • npm
  • Socket score

Version published
Maintainers
7
Created

What is koa-send?

The koa-send package is a utility for Koa applications that allows you to serve static files. It is commonly used to serve files such as HTML, CSS, JavaScript, images, and other static assets from a directory on the server.

What are koa-send's main functionalities?

Serving Static Files

This feature allows you to serve static files from a specified path. In this example, when a request is made to '/static', the server responds with the file located at 'path/to/static/file.html'.

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

app.use(async (ctx) => {
  if (ctx.path === '/static') {
    await send(ctx, 'path/to/static/file.html');
  }
});

app.listen(3000);

Serving Files from a Directory

This feature allows you to serve files from a directory. In this example, any request path will be mapped to a file in the 'public' directory relative to the current directory.

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

app.use(async (ctx) => {
  await send(ctx, ctx.path, { root: __dirname + '/public' });
});

app.listen(3000);

Setting Cache Control Headers

This feature allows you to set cache control headers for the served files. In this example, the 'maxage' option is set to 1 hour, which will set the 'Cache-Control' header to cache the file for 1 hour.

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

app.use(async (ctx) => {
  await send(ctx, 'path/to/static/file.html', { maxage: 1000 * 60 * 60 }); // 1 hour
});

app.listen(3000);

Other packages similar to koa-send

Keywords

FAQs

Package last updated on 23 Jul 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