Gathering detailed insights and metrics for on-finished
Gathering detailed insights and metrics for on-finished
Gathering detailed insights and metrics for on-finished
Gathering detailed insights and metrics for on-finished
@types/on-finished
TypeScript definitions for on-finished
xprezzo-on-finished
Execute a callback when a request closes, finishes, or errors
front-on-finished
Execute a callback when a request closes, finishes, or errors
@ryancavanaugh/on-finished
Type definitions for on-finished v2.2.0 from https://www.github.com/DefinitelyTyped/DefinitelyTyped
Execute a callback when a request closes, finishes, or errors
npm install on-finished
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
400 Stars
290 Commits
48 Forks
16 Watchers
10 Branches
28 Contributors
Updated on Jun 08, 2025
Latest Version
2.4.1
Package Id
on-finished@2.4.1
Unpacked Size
13.36 kB
Size
4.93 kB
File Count
5
NPM Version
8.1.2
Node Version
16.13.1
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Execute a callback when a HTTP request closes, finishes, or errors.
This is a Node.js module available through the
npm registry. Installation is done using the
npm install
command:
1$ npm install on-finished
1var onFinished = require('on-finished')
Attach a listener to listen for the response to finish. The listener will be invoked only once when the response finished. If the response finished to an error, the first argument will contain the error. If the response has already finished, the listener will be invoked.
Listening to the end of a response would be used to close things associated with the response, like open files.
Listener is invoked as listener(err, res)
.
1onFinished(res, function (err, res) {
2 // clean up open fds, etc.
3 // err contains the error if request error'd
4})
Attach a listener to listen for the request to finish. The listener will be invoked only once when the request finished. If the request finished to an error, the first argument will contain the error. If the request has already finished, the listener will be invoked.
Listening to the end of a request would be used to know when to continue after reading the data.
Listener is invoked as listener(err, req)
.
1var data = '' 2 3req.setEncoding('utf8') 4req.on('data', function (str) { 5 data += str 6}) 7 8onFinished(req, function (err, req) { 9 // data is read unless there is err 10})
Determine if res
is already finished. This would be useful to check and
not even start certain operations if the response has already finished.
Determine if req
is already finished. This would be useful to check and
not even start certain operations if the request has already finished.
The meaning of the CONNECT
method from RFC 7231, section 4.3.6:
The CONNECT method requests that the recipient establish a tunnel to the destination origin server identified by the request-target and, if successful, thereafter restrict its behavior to blind forwarding of packets, in both directions, until the tunnel is closed. Tunnels are commonly used to create an end-to-end virtual connection, through one or more proxies, which can then be secured using TLS (Transport Layer Security, [RFC5246]).
In Node.js, these request objects come from the 'connect'
event on
the HTTP server.
When this module is used on a HTTP CONNECT
request, the request is
considered "finished" immediately, due to limitations in the Node.js
interface. This means if the CONNECT
request contains a request entity,
the request will be considered "finished" even before it has been read.
There is no such thing as a response object to a CONNECT
request in
Node.js, so there is no support for one.
The meaning of the Upgrade
header from RFC 7230, section 6.1:
The "Upgrade" header field is intended to provide a simple mechanism for transitioning from HTTP/1.1 to some other protocol on the same connection.
In Node.js, these request objects come from the 'upgrade'
event on
the HTTP server.
When this module is used on a HTTP request with an Upgrade
header, the
request is considered "finished" immediately, due to limitations in the
Node.js interface. This means if the Upgrade
request contains a request
entity, the request will be considered "finished" even before it has been
read.
There is no such thing as a response object to a Upgrade
request in
Node.js, so there is no support for one.
The following code ensures that file descriptors are always closed once the response finishes.
1var destroy = require('destroy') 2var fs = require('fs') 3var http = require('http') 4var onFinished = require('on-finished') 5 6http.createServer(function onRequest (req, res) { 7 var stream = fs.createReadStream('package.json') 8 stream.pipe(res) 9 onFinished(res, function () { 10 destroy(stream) 11 }) 12})
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
GitHub workflow tokens follow principle of least privilege
Details
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
SAST tool detected but not run on all commits
Details
Reason
dependency not pinned by hash detected -- score normalized to 5
Details
Reason
2 commit(s) and 3 issue activity found in the last 90 days -- score normalized to 4
Reason
Found 5/30 approved changesets -- score normalized to 1
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-06-30
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