Connect Logging Middleware
connect-logger is a minimalistic Connect/Express middleware designed for logging incoming HTTP requests. Released in 2013, its latest and only version is `0.0.1`. The package primarily offers basic request logging with customizable format strings for date, status, method, URL, route, and response time. It allows for moment.js-style date formatting, though `moment` itself is not a direct dependency but rather an implied style guide. Due to its age and lack of updates, it is not compatible with modern Node.js versions, contemporary Express APIs, or ES Modules. Its lack of maintenance makes it unsuitable for production use in current environments, as it predates many standard logging practices and security considerations now common in web development.
Common errors
-
TypeError: Cannot read properties of undefined (reading 'call')
cause This error often occurs when `connect-logger` attempts to use internal Express/Connect APIs that have changed significantly or no longer exist in newer versions of Express.fixThe only fix is to replace `connect-logger` with a modern, maintained logging middleware like `morgan` or `pino-http`. -
SyntaxError: Cannot use import statement outside a module
cause Attempting to use `import connectLogger from 'connect-logger'` in a CommonJS context or when the package itself only provides CommonJS exports.fixUse `const connectLogger = require('connect-logger');`. However, given the package's age, consider migrating to a modern logging solution.
Warnings
- breaking The package `connect-logger` has not been updated since 2013 (version 0.0.1). It is highly incompatible with modern Node.js versions (e.g., Node.js 14+), Express.js versions (4.x+), and may cause runtime errors or unexpected behavior due to API changes in underlying frameworks.
- gotcha This package is written exclusively in CommonJS. Attempting to use `import` statements (ES Modules) will result in a runtime error.
- gotcha There are significant security risks associated with using unmaintained packages. `connect-logger` has not received any security patches or updates for over a decade, making it vulnerable to known and unknown exploits, and potentially exposing your application to supply chain attacks or data breaches.
- deprecated The `moment.js` library, which is implicitly referenced for date formatting, is now in maintenance mode and no longer recommended for new projects. Its API is also not directly integrated but rather an example for the `date` option, meaning `connect-logger` does not handle date formatting directly through moment.
Install
-
npm install connect-logger -
yarn add connect-logger -
pnpm add connect-logger
Imports
- connectLogger
const connectLogger = require('connect-logger');
Quickstart
const express = require('express');
const connectLogger = require('connect-logger');
const app = express();
// Basic usage with default options
app.use(connectLogger());
// Example with custom format and date options
app.use(connectLogger({
format: '%date %status %method %url - Response time: %time ms',
date: 'YYYY-MM-DD HH:mm:ss'
}));
app.get('/', (req, res) => {
res.send('Hello from connect-logger example!');
});
app.get('/test', (req, res) => {
res.send('Another page!');
});
const port = 3000;
app.listen(port, () => {
console.log(`Server listening on http://localhost:${port}`);
});