{"id":17735,"library":"knex-logger","title":"Knex.js Query Logger for Express","description":"This package provides Express middleware designed to log queries executed by Knex.js. It intercepts Knex query events and outputs them, typically to the console, for debugging and monitoring purposes within an Express application. The package is at version 0.1.0 and has seen no updates since its initial release over eight years ago, indicating it is abandoned. Its release cadence was effectively a single release. Key differentiators, if any existed, are now moot due to its lack of maintenance, especially concerning compatibility with modern Knex.js, Express, and Node.js versions which have evolved significantly since its last update. Users should be aware of potential incompatibilities and security risks.","status":"abandoned","version":"0.1.0","language":"javascript","source_language":"en","source_url":"git://github.com/wbyoung/knex-logger","tags":["javascript","knex","express","log","debug","query","sql","postgresql","mysql"],"install":[{"cmd":"npm install knex-logger","lang":"bash","label":"npm"},{"cmd":"yarn add knex-logger","lang":"bash","label":"yarn"},{"cmd":"pnpm add knex-logger","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required to initialize the logger middleware and capture query events.","package":"knex","optional":false},{"reason":"The package functions as Express middleware and requires an Express application instance.","package":"express","optional":false}],"imports":[{"note":"This package uses CommonJS and does not officially support ES modules. Direct `import` statements will likely fail without a transpiler.","wrong":"import knexLogger from 'knex-logger';","symbol":"knexLogger","correct":"const knexLogger = require('knex-logger');"}],"quickstart":{"code":"// knexfile.js\nconst path = require('path');\nmodule.exports = {\n  development: {\n    client: 'sqlite3',\n    connection: {\n      filename: path.resolve(__dirname, './dev.sqlite3')\n    },\n    useNullAsDefault: true,\n  },\n};\n\n// app.js\nconst express = require('express');\nconst knex = require('knex');\nconst knexLogger = require('knex-logger'); // CommonJS import as per package status\nconst path = require('path');\n\nconst env = process.env.NODE_ENV || 'development';\nconst knexConfig = require('./knexfile.js')[env];\nconst db = knex(knexConfig); // Initialize Knex instance\n\nconst app = express();\n\n// Apply the knex-logger middleware\napp.use(knexLogger(db));\n\n// Example route that uses Knex\napp.get('/users', async (req, res) => {\n  try {\n    const users = await db('users').select('*');\n    res.json(users);\n  } catch (error) {\n    console.error('Error fetching users:', error);\n    res.status(500).send('Internal Server Error');\n  }\n});\n\n// Basic setup to listen\nconst PORT = process.env.PORT || 3000;\napp.listen(PORT, () => {\n  console.log(`Server listening on port ${PORT}`);\n  // Create a dummy table if it doesn't exist for demonstration\n  db.schema.hasTable('users').then(exists => {\n    if (!exists) {\n      return db.schema.createTable('users', table => {\n        table.increments('id').primary();\n        table.string('name');\n        table.string('email');\n      })\n      .then(() => db('users').insert([{ name: 'Alice', email: 'alice@example.com' }, { name: 'Bob', email: 'bob@example.com' }]));\n    }\n  });\n});","lang":"javascript","description":"This quickstart demonstrates how to integrate `knex-logger` as Express middleware to automatically log all database queries made by a Knex.js instance."},"warnings":[{"fix":"Migrate to a maintained logging solution for Knex.js, or implement custom query logging using Knex's built-in event listeners (`query`, `query-response`, `error`).","message":"The `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.","severity":"breaking","affected_versions":"all versions (0.1.0)"},{"fix":"Do not use this package in production. If logging is required, use actively maintained alternatives or Knex's native logging capabilities.","message":"Using 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.","severity":"gotcha","affected_versions":"all versions (0.1.0)"},{"fix":"Ensure 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.","message":"The 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.","severity":"gotcha","affected_versions":"all versions (0.1.0)"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Verify 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)`.","cause":"The 'knex-logger' package failed to load or was imported incorrectly, resulting in 'knexLogger' being undefined or not a function.","error":"TypeError: app.use() requires a middleware function but got a undefined"},{"fix":"Ensure 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.","cause":"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.","error":"Queries are not being logged to the console."},{"fix":"Install 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.","cause":"A dependency required by 'knex-logger' or its usage (`knex`, `express`, or `debug`) is not installed in the project.","error":"Error: Cannot find module 'knex'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}