Installations
npm install koa-files
Developer Guide
Typescript
No
Module System
ESM
Min. Node Version
>=8.0.0
Node Version
22.12.0
NPM Version
10.9.0
Score
65.5
Supply Chain
96.9
Quality
83.3
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (79.17%)
JavaScript (20.83%)
validate.email 🚀
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Developer
nuintun
Download Statistics
Total Downloads
12,048
Last Day
8
Last Week
22
Last Month
149
Last Year
3,577
GitHub Statistics
MIT License
8 Stars
351 Commits
1 Watchers
3 Branches
1 Contributors
Updated on Feb 26, 2025
Bundle Size
7.58 kB
Minified
3.22 kB
Minified + Gzipped
Package Meta Information
Latest Version
4.0.1
Package Id
koa-files@4.0.1
Unpacked Size
59.90 kB
Size
14.54 kB
File Count
35
NPM Version
10.9.0
Node Version
22.12.0
Published on
Dec 20, 2024
Total Downloads
Cumulative downloads
Total Downloads
12,048
Last Day
14.3%
8
Compared to previous day
Last Week
-4.3%
22
Compared to previous week
Last Month
-35.5%
149
Compared to previous month
Last Year
129.1%
3,577
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
3
Peer Dependencies
1
koa-files
A static files serving middleware for koa.
Installation
1$ npm install koa-files
API
1import { Middleware } from 'koa'; 2import fs, { Stats } from 'node:fs'; 3 4interface Headers { 5 [key: string]: string | string[]; 6} 7 8interface IgnoreFunction { 9 (path: string): boolean | Promise<boolean>; 10} 11 12interface HeadersFunction { 13 (path: string, stats: Stats): Promise<Headers | void> | Headers | void; 14} 15 16export interface FileSystem { 17 stat: typeof fs.stat; 18 open: typeof fs.open; 19 read: typeof fs.read; 20 close: typeof fs.close; 21} 22 23export interface Options { 24 fs?: FileSystem; 25 defer?: boolean; 26 etag?: boolean; 27 acceptRanges?: boolean; 28 lastModified?: boolean; 29 highWaterMark?: number; 30 ignore?: IgnoreFunction; 31 headers?: Headers | HeadersFunction; 32} 33 34export function server(root: string, options?: Options): Middleware;
root
- Root directory string.
- Nothing above this root directory can be served.
Options
fs
- Defaults to
node:fs
. - The file system to used.
defer
- Defaults to
false
. - If true, serves after
await next()
. - Allowing any downstream middleware to respond first.
etag
- Defaults to
true
. - Enable or disable etag generation.
- Use weak etag internally.
- Can be overridden by the
headers
.
acceptRanges
- Defaults to
true
. - Enable or disable accepting ranged requests.
- Disabling this will not send Accept-Ranges and ignore the contents of the Range request header.
- Can be overridden by the
headers
.
lastModified
- Defaults to
true
. - Enable or disable Last-Modified header.
- Use the file system's last modified value.
- Can be overridden by the
headers
.
highWaterMark
- Defaults to
65536
(64 KiB). - Set the high water mark for the read stream.
ignore
- Defaults to
undefined
. - Function that determines if a file should be ignored.
headers
- Defaults to
undefined
. - Set headers to be sent.
- See docs: Headers in MDN.
Example
1/** 2 * @module server 3 * @license MIT 4 * @author nuintun 5 */ 6 7import Koa from 'koa'; 8import { server } from 'koa-files'; 9 10const app = new Koa(); 11const port = process.env.PORT || 80; 12 13// Static files server 14app.use( 15 server('tests', { 16 headers: { 17 'Cache-Control': 'public, max-age=31557600' 18 } 19 }) 20); 21 22/** 23 * @function httpError 24 * @param {NodeJS.ErrnoException} error 25 * @returns {boolean} 26 */ 27function httpError(error) { 28 return /^(EOF|EPIPE|ECANCELED|ECONNRESET|ECONNABORTED)$/i.test(error.code); 29} 30 31// Listen error event 32app.on('error', error => { 33 !httpError(error) && console.error(error); 34}); 35 36// Start server 37app.listen(port, () => { 38 console.log(`> server running at: 127.0.0.1:${port}`); 39});
Features
Support multipart range and download resumption.
License
MIT

No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
30 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
packaging workflow detected
Details
- Info: Project packages its releases by way of GitHub Actions.: .github/workflows/npm-publish.yml:6
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 existing vulnerabilities detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Info: jobLevel 'contents' permission set to 'read': .github/workflows/npm-publish.yml:9
- Warn: no topLevel permission defined: .github/workflows/npm-publish.yml:1
- Info: no jobLevel write permissions found
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/nuintun/koa-files/npm-publish.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/nuintun/koa-files/npm-publish.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/nuintun/koa-files/npm-publish.yml/main?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Score
5.5
/10
Last Scanned on 2025-02-17
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More