Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
@types/send
Advanced tools
TypeScript definitions for send
The @types/send package provides TypeScript type definitions for the 'send' package, which is a utility for streaming files from the file system as an HTTP response. It supports directory indexes, conditional GET requests, and other high-level features. The @types/send package itself does not implement these functionalities but provides type definitions to help TypeScript developers use the 'send' package more effectively by offering compile-time type checking and IntelliSense support in code editors.
Serving a file
This code demonstrates how to serve a file using the 'send' package. It creates an HTTP server that listens on port 3000 and uses the 'send' function to stream a file from the file system to the response. The @types/send package provides type definitions for this usage.
import send from 'send';
import http from 'http';
http.createServer((req, res) => {
send(req, '/path/to/file.txt').pipe(res);
}).listen(3000);
Setting custom headers
This example shows how to set custom HTTP headers before sending the file. It listens for the 'headers' event and then sets the 'Cache-Control' header. The @types/send package provides type definitions for these event handlers and method chaining.
import send from 'send';
import http from 'http';
http.createServer((req, res) => {
send(req, '/path/to/file.txt')
.on('headers', (res, path, stat) => {
res.setHeader('Cache-Control', 'public, max-age=3600');
})
.pipe(res);
}).listen(3000);
Express is a web application framework for Node.js, designed for building web applications and APIs. It includes similar file serving capabilities through the 'express.static' middleware. While 'send' focuses solely on streaming files, Express provides a broader range of web server functionalities. The @types/express package offers TypeScript definitions for Express.
koa-send is a file serving utility for Koa, a web framework for Node.js. It is similar to 'send' but designed to work within the Koa ecosystem. koa-send supports serving files, setting custom headers, and more, tailored for Koa's middleware architecture. The @types/koa-send package provides TypeScript definitions for koa-send.
npm install --save @types/send
This package contains type definitions for send (https://github.com/pillarjs/send).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/send.
These definitions were written by Mike Jerred, and Piotr Błażejewicz.
FAQs
TypeScript definitions for send
The npm package @types/send receives a total of 11,919,911 weekly downloads. As such, @types/send popularity was classified as popular.
We found that @types/send demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.