Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
xprezzo-finalhandler
Advanced tools
xprezzo-finalhandler provides function to invoke as the final step to respond to HTTP request.
This is a xprezzo module available through the
npm registry. Installation is done using the
npm install
command:
$ npm install xprezzo-finalhandler
var finalhandler = require('xprezzo-finalhandler')
Returns function to be invoked as the final step for the given req
and res
.
This function is to be invoked as fn(err)
. If err
is falsy, the handler will
write out a 404 response to the res
. If it is truthy, an error response will
be written out to the res
.
When an error is written, the following information is added to the response:
res.statusCode
is set from err.status
(or err.statusCode
). If
this value is outside the 4xx or 5xx range, it will be set to 500.res.statusMessage
is set according to the status code.env
is
'production'
, otherwise will be err.stack
.err.headers
object.The final handler will also unpipe anything from req
when it is invoked.
By default, the environment is determined by NODE_ENV
variable, but it can be
overridden by this option.
Provide a function to be called with the err
when it exists. Can be used for
writing errors to a central location without excessive function generation. Called
as onerror(err, req, res)
.
var finalhandler = require('xprezzo-finalhandler')
var http = require('http')
var server = http.createServer(function (req, res) {
var done = finalhandler(req, res)
done()
})
server.listen(3000)
var finalhandler = require('xprezzo-finalhandler')
var fs = require('fs')
var http = require('http')
var server = http.createServer(function (req, res) {
var done = finalhandler(req, res)
fs.readFile('index.html', function (err, buf) {
if (err) return done(err)
res.setHeader('Content-Type', 'text/html')
res.end(buf)
})
})
server.listen(3000)
var finalhandler = require('xprezzo-finalhandler')
var http = require('http')
var serveStatic = require('serve-static')
var serve = serveStatic('public')
var server = http.createServer(function (req, res) {
var done = finalhandler(req, res)
serve(req, res, done)
})
server.listen(3000)
var finalhandler = require('xprezzo-finalhandler')
var fs = require('fs')
var http = require('http')
var server = http.createServer(function (req, res) {
var done = finalhandler(req, res, { onerror: logerror })
fs.readFile('index.html', function (err, buf) {
if (err) return done(err)
res.setHeader('Content-Type', 'text/html')
res.end(buf)
})
})
server.listen(3000)
function logerror (err) {
console.error(err.stack || err.toString())
}
Xprezzo and related projects are maintained by Ben Ajenoui and sponsored by SEO Hero.
FAQs
xprezzo final http responder
We found that xprezzo-finalhandler 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
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.