Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
knexLogger
✓ const knexLogger = require('knex-logger');
✗ import knexLogger from 'knex-logger';
This package uses CommonJS and does not officially support ES modules. Direct `import` statements will likely fail without a transpiler.
This quickstart demonstrates how to integrate `knex-logger` as Express middleware to automatically log all database queries made by a Knex.js instance.
// knexfile.js
const path = require('path');
module.exports = {
development: {
client: 'sqlite3',
connection: {
filename: path.resolve(__dirname, './dev.sqlite3')
},
useNullAsDefault: true,
},
};
// app.js
const express = require('express');
const knex = require('knex');
const knexLogger = require('knex-logger'); // CommonJS import as per package status
const path = require('path');
const env = process.env.NODE_ENV || 'development';
const knexConfig = require('./knexfile.js')[env];
const db = knex(knexConfig); // Initialize Knex instance
const app = express();
// Apply the knex-logger middleware
app.use(knexLogger(db));
// Example route that uses Knex
app.get('/users', async (req, res) => {
try {
const users = await db('users').select('*');
res.json(users);
} catch (error) {
console.error('Error fetching users:', error);
res.status(500).send('Internal Server Error');
}
});
// Basic setup to listen
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}`);
// Create a dummy table if it doesn't exist for demonstration
db.schema.hasTable('users').then(exists => {
if (!exists) {
return db.schema.createTable('users', table => {
table.increments('id').primary();
table.string('name');
table.string('email');
})
.then(() => db('users').insert([{ name: 'Alice', email: 'alice@example.com' }, { name: 'Bob', email: 'bob@example.com' }]));
}
});
});
Debug
Known issues
breakingThe `knex-logger` package is severely outdated (v0.1.0, last updated 8+ years ago) and is incompatible with modern versions of Knex.js, Express, and Node.js. It uses deprecated APIs and will likely not function as expected or at all with current ecosystem versions.fixMigrate to a maintained logging solution for Knex.js, or implement custom query logging using Knex's built-in event listeners (`query`, `query-response`, `error`).
affects: all versions (0.1.0)
gotchaUsing this package in a production environment poses significant security risks due to its abandoned status. It has not received security updates and may contain vulnerabilities that could be exploited.fixDo not use this package in production. If logging is required, use actively maintained alternatives or Knex's native logging capabilities.
affects: all versions (0.1.0)
gotchaThe package relies on CommonJS module syntax (`require`). Attempting to import it using ES module syntax (`import`) in an ESM-only project will result in module resolution errors unless a transpilation step is configured.fixEnsure your project is configured for CommonJS or use a build step (e.g., Webpack, Rollup, Babel) to transpile the module. For modern projects, consider alternatives that provide native ESM support.
affects: all versions (0.1.0)
Errors
Common errors & fixes
TypeError: app.use() requires a middleware function but got a undefined
The 'knex-logger' package failed to load or was imported incorrectly, resulting in 'knexLogger' being undefined or not a function.
fixVerify that 'knex-logger' is installed, and ensure it's imported using CommonJS: `const knexLogger = require('knex-logger');`. Also, check if Knex.js instance is correctly passed to `knexLogger(knexInstance)`. Queries are not being logged to the console.
The Knex.js instance passed to knex-logger might not be the one actively used for database operations, or the middleware is not correctly applied to the Express app.
fixEnsure that `app.use(knexLogger(yourKnexInstance))` is called before any routes that perform database queries, and that `yourKnexInstance` is the exact Knex instance performing those queries.
Error: Cannot find module 'knex'
A dependency required by 'knex-logger' or its usage (`knex`, `express`, or `debug`) is not installed in the project.
fixInstall the missing dependency using npm: `npm install knex express debug`. Note that 'debug' might be an internal dependency and 'knex' and 'express' are external usage dependencies.
Audit
Dependencies
knexrequiredRequired to initialize the logger middleware and capture query events.
expressrequiredThe package functions as Express middleware and requires an Express application instance.