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

@types/koa-send

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/koa-send

TypeScript definitions for koa-send

  • 3.3.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
137K
increased by22.51%
Maintainers
1
Weekly downloads
 
Created

What is @types/koa-send?

@types/koa-send provides TypeScript definitions for the koa-send package, which is used to serve static files in a Koa application.

What are @types/koa-send's main functionalities?

Serving Static Files

This feature allows you to serve static files from a specified path. In this example, when the user accesses the '/static' route, the server will respond with the file located at 'path/to/file.txt'.

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/file.txt');
  }
});

app.listen(3000);

Setting Root Directory

This feature allows you to set a root directory for serving static files. In this example, the server will look for 'file.txt' in the 'public' directory located in the current directory.

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

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

app.listen(3000);

Setting Cache Control

This feature allows you to set cache control headers for the served files. In this example, the 'maxAge' option is set to 1 hour, meaning the file will be cached for 1 hour.

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

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

app.listen(3000);

Other packages similar to @types/koa-send

FAQs

Package last updated on 09 Nov 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