{"id":18698,"library":"querymen","title":"Querymen","description":"Querymen is a querystring parsing middleware for Express.js and MongoDB, enabling automatic pagination, sorting, field selection, and custom query filters from URL parameters. Version 2.1.4 is the current stable release, with infrequent updates. It provides a declarative schema to map query parameters to MongoDB query operators like `$gte`, `$in`, and `$exists`, and integrates with mongoose-keywords for full-text search. Compared to alternatives like express-api-query-parser, it offers a more opinionated and schema-driven approach with built-in pagination defaults.","status":"maintenance","version":"2.1.4","language":"javascript","source_language":"en","source_url":"https://github.com/diegohaz/querymen","tags":["javascript","mongo","express","node","query","querystring","param","mongodb","expressjs"],"install":[{"cmd":"npm install querymen","lang":"bash","label":"npm"},{"cmd":"yarn add querymen","lang":"bash","label":"yarn"},{"cmd":"pnpm add querymen","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Middleware designed for Express.js; requires Express request/response objects","package":"express","optional":false},{"reason":"Commonly used with Mongoose for MongoDB queries, though not strictly required","package":"mongoose","optional":true}],"imports":[{"note":"ESM style is recommended; CJS require is also supported but less common.","wrong":"const query = require('querymen').middleware","symbol":"middleware","correct":"import { middleware as query } from 'querymen'"},{"note":"Schema is a named export, not a default export.","wrong":"import Schema from 'querymen'","symbol":"Schema","correct":"import { Schema } from 'querymen'"},{"note":"The parsed data is attached to req.querymen, not req.query.","wrong":"const { query } = req;","symbol":"querymen object","correct":"const { querymen } = req;"}],"quickstart":{"code":"import express from 'express';\nimport { middleware as query } from 'querymen';\n\nconst app = express();\n\napp.get('/posts', query(), (req, res) => {\n  const { query, select, cursor } = req.querymen;\n  // Example: fetch posts with pagination and sorting from query string\n  // User requests: /posts?page=2&limit=10&sort=-createdAt\n  Post.find(query, select, cursor, (err, posts) => {\n    res.json(posts);\n  });\n});\n\napp.listen(3000);","lang":"typescript","description":"Demonstrates basic usage of Querymen middleware with Express, handling pagination and sorting from query string parameters."},"warnings":[{"fix":"Access parsed data via req.querymen (e.g., req.querymen.query).","message":"The parsed query object is attached to req.querymen, not req.query. Overwriting req.query is not supported.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Use `{ type: Boolean }` in schema definition; query values become `true`/`false`.","message":"Boolean parameters like `active=true` are parsed as JSON booleans, not strings. Ensure your MongoDB schema expects boolean values.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Define a custom schema with a `RegExp` type parameter and specify `paths` and `operator` for custom search behavior.","message":"The default `q` parameter for full-text search is designed for mongoose-keywords and may not work with other search setups.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"For other array operators (e.g., `$all`), define a custom schema with a custom formatter.","message":"Array parameters like `tags=world,travel` are split by comma and used with `$in` operator. No support for other array operators out of the box.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Ensure date strings are ISO 8601 compliant (e.g., '2016-04-23') to avoid parsing issues.","message":"Date parameters are parsed via `new Date(value)`. Invalid date strings may result in `Invalid Date` objects or unexpected behavior.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Ensure the middleware is applied to the route: `app.get('/posts', query(), handler)`.","cause":"Attempting to access req.querymen before the middleware has run or the route is incorrectly configured.","error":"Cannot read property 'query' of undefined"},{"fix":"Use `import querymen from 'querymen'` and then `const query = querymen.middleware` or enable `esModuleInterop` in TypeScript.","cause":"Using a bundler that does not support named exports from CommonJS modules (e.g., Webpack with strict ESM).","error":"export 'middleware' was not found in 'querymen'"},{"fix":"Use `import { Schema } from 'querymen'` (named export) or `const { Schema } = require('querymen')`.","cause":"Using `import { Schema } from 'querymen'` but expecting a default export instead of a named export.","error":"Schema is not a constructor"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}