watson / request-stats Goto Github PK
View Code? Open in Web Editor NEWGet stats on your Node.js HTTP server requests
License: MIT License
Get stats on your Node.js HTTP server requests
License: MIT License
This does not work.
const app: Application = express();
...
// Request Stats
var stats = requestStats(app);
console.log("stats", stats);
stats.on("request", function (req) {
// every second, print stats
var interval = setInterval(function () {
var progress = req.progress();
console.log(progress);
if (progress.completed) clearInterval(interval);
}, 1000);
});
Hey hey,
It looks like it only works for http servers. I made a quick fix to make it works.
index.js:
'use strict'
var http = require('http')
var https = require('https')
var StatsEmitter = require('./lib/stats_emitter')
module.exports = function (req, res, onStats) {
var statsEmitter = new StatsEmitter()
if (req instanceof http.Server || req instanceof https.Server) {
statsEmitter._server(req, res);
}
else
if (req instanceof http.IncomingMessage) {
statsEmitter._request(req, res, onStats);
}
return statsEmitter
}
main.js
'use strict';
const express = require('express');
const requestStats = require('request-stats');
var app = express();
app.use('/api', (req, res, next) => {
console.log('req.url:', req.url);
console.log('req.originalUrl:', req.originalUrl);
res.end('OK');
});
var server = app.listen(process.env.PORT || 3000, () => {
console.log('Listening on port %d', server.address().port);
});
requestStats(server, (stats) => {
console.log('stats.req.path:', stats.req.path);
});
$ node main.js
Listening on port 3000
$ curl http://localhost:3000/api/user
req.url: /user
req.originalUrl: /api/user
stats.req.path: /user
Hi,
In version 3.0.0 of the package the test file is also published to the npm registry.
Would it be possible to not publish it?
Regards
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.