
Security News
Deno 2.4 Brings Back deno bundle, Improves Dependency Management and Observability
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
connect-static-file
Advanced tools
Connect/express middleware to serve a single static file
var express = require('express');
var staticFile = require('connect-static-file');
var app = express();
var path = 'path/to/file.txt';
var options = {};
app.use('/foo.txt', staticFile(path, options));
Enable or disable etag generation, defaults to true.
If a given file doesn't exist, try appending one of the given extensions,
in the given order. By default, this is disabled (set to false
). An
example value that will serve extension-less HTML files: ['html', 'htm']
.
This is skipped if the requested file already has an extension.
Enable or disable Last-Modified
header, defaults to true. Uses the file
system's last modified value.
Provide a max-age in milliseconds for http caching, defaults to 0. This can also be a string accepted by the ms module.
Any additional headers you would like to set on the response. This is a plain old javascript object: headers: {'X-Foo': 'bar'}
If set, assume the static file has been encoded using the specified encoding. For example encoded: 'gzip'
. This value must be a valid Content-Encoding
token.
If the browser does not support this encoding (the encoding is not specified in the Accept-Encoding
request header), this middleware will pass on the request to the next middleware. The Content-Encoding
header will be set so that the browser will uncompress the file on the fly.
This is useful if you are compressing your static files beforehand:
app.use('/bundle.js', staticFile('generated/bundle.js.gz', {encoded: 'gzip'}));
// If the file is missing, or if the browser does not support gzip, use this one instead:
app.use('/bundle.js', staticFile('generated/bundle.js'));
If you would like to server an entire directory of possible gziped files, take a look at connect-gzip-static or ecstatic. If you would like dynamic gzip compression, try compression
FAQs
connect and express middleware to serve a single static file
The npm package connect-static-file receives a total of 3,313 weekly downloads. As such, connect-static-file popularity was classified as popular.
We found that connect-static-file demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.