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

send

Package Overview
Dependencies
Maintainers
3
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

send

Better streaming static file server with Range and conditional-GET support

  • 1.1.0
  • next
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
37M
increased by2.98%
Maintainers
3
Weekly downloads
 
Created

What is send?

The 'send' npm package is a library for streaming files from the file system as an HTTP response. It handles range requests, redirects, and errors, and is built with security in mind. It is often used to serve static files in web applications.

What are send's main functionalities?

Serving static files

This code creates an HTTP server that serves a static file using the send package. When a request is made to the server, it streams the specified file as the response.

const send = require('send');
const http = require('http');

http.createServer(function(req, res){
  send(req, '/path/to/public/index.html').pipe(res);
}).listen(3000);

Handling range requests

This code demonstrates how to handle HTTP range requests for partial content delivery, such as serving video files that can be streamed.

const send = require('send');
const http = require('http');

http.createServer(function(req, res){
  send(req, '/path/to/public/video.mp4')
    .on('headers', function (res, path, stat) {
      res.setHeader('Accept-Ranges', 'bytes');
    })
    .pipe(res);
}).listen(3000);

Custom error handling

This code shows how to handle errors when a file is not found or another error occurs while trying to stream a file.

const send = require('send');
const http = require('http');

http.createServer(function(req, res){
  send(req, '/path/to/public/non-existent-file.html')
    .on('error', function(err) {
      res.statusCode = err.status || 500;
      res.end(err.message);
    })
    .pipe(res);
}).listen(3000);

Other packages similar to send

Keywords

FAQs

Package last updated on 10 Sep 2024

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