{"id":11450,"library":"node-restify-validation","title":"Node-Restify Validation","description":"node-restify-validation is a Node.js library designed to integrate request validation directly into REST services built using the `node-restify` framework. It allows developers to define validation schemas for path parameters (resources), query parameters, request body content, and HTTP headers directly within the `restify` route definition object. The current stable version is 1.3.0, released after 1.1.0, but the project explicitly states \"Maintener wanted\" in its README, indicating an abandoned or maintenance-only status with no active development. Its primary differentiator is its close integration with `restify`'s route definition, aiming to keep validation logic co-located with the route itself. It supports basic validation rules like `isRequired`, `isIn`, `isEmail`, `isNatural`, `isDictionary`, and `isObject` with nested properties and array validations.","status":"abandoned","version":"1.3.0","language":"javascript","source_language":"en","source_url":"git://github.com/z0mt3c/node-restify-validation","tags":["javascript","rest","api","restify","validation"],"install":[{"cmd":"npm install node-restify-validation","lang":"bash","label":"npm"},{"cmd":"yarn add node-restify-validation","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-restify-validation","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core dependency for building REST services that this library validates. Requires restify >= 2.6.0.","package":"restify","optional":false}],"imports":[{"note":"This library is written for CommonJS (`require`) environments. Direct ESM `import` statements may not work without transpilation or specific Node.js configuration.","wrong":"import { validationPlugin } from 'node-restify-validation';","symbol":"validationPlugin","correct":"const restifyValidation = require('node-restify-validation');\n// then use restifyValidation.validationPlugin"},{"note":"Validation rules are defined directly as a `validation` property within the route object passed to Restify methods like `server.get`, `server.post`, etc.","symbol":"validation route property","correct":"server.get({ url: '/test', validation: { ... } }, handler)"}],"quickstart":{"code":"const restify = require('restify');\nconst restifyValidation = require('node-restify-validation');\n\nconst server = restify.createServer();\nserver.use(restify.queryParser());\nserver.use(restify.bodyParser()); // Required for 'content' validation\nserver.use(restifyValidation.validationPlugin({\n    errorsAsArray: false,\n    forbidUndefinedVariables: false,\n    errorHandler: restify.errors.InvalidArgumentError\n}));\n\nserver.get({\n    url: '/test/:name',\n    validation: {\n        resources: { // Path parameters\n            name: { isRequired: true, isIn: ['foo', 'bar'] }\n        },\n        queries: { // Query parameters\n            status: { isRequired: true, isIn: ['foo', 'bar'] },\n            email: { isRequired: false, isEmail: true },\n            age: { isRequired: true, isNatural: true }\n        },\n        headers: { // HTTP Headers\n            requestid: { isRequired: true }\n        }\n    }\n}, function (req, res, next) {\n    res.send(200, { message: `Hello ${req.params.name}, your status is ${req.query.status}.` });\n    return next();\n});\n\nserver.listen(8001, function () {\n    console.log('%s listening at %s', server.name, server.url);\n});","lang":"javascript","description":"Initializes a Restify server with the validation plugin and defines a GET route with path, query, and header parameter validation rules, demonstrating how to attach validation schemas directly to routes."},"warnings":[{"fix":"Consider migrating to an actively maintained validation library for Restify (if one exists) or forking the project and taking on maintenance responsibilities if continued use is critical. Restify itself has seen limited recent activity.","message":"The project is explicitly marked as 'Maintener wanted' in its README. This indicates that the library is unmaintained, will not receive bug fixes, security patches, or new features. Using it in production carries significant risk.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Ensure that your project's `package.json` specifies a `restify` dependency of version `2.6.0` or higher.","message":"This library has a strict dependency on `restify >= 2.6.0`. Using older versions of `restify` will lead to runtime errors due to changes in Restify's route object API that `node-restify-validation` relies upon.","severity":"gotcha","affected_versions":"<1.0.0 (of node-restify-validation used with restify < 2.6.0)"},{"fix":"Always use `const restifyValidation = require('node-restify-validation');` for importing the module in your Node.js applications.","message":"The library is primarily designed for CommonJS (`require()`) environments. While Node.js offers some interoperability, using ES Module `import` syntax directly might cause issues without proper configuration or transpilation.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Implement a global error handler for your Restify server using `server.on('restifyError', function (req, res, err, next) { /* handle error */ });` to catch `InvalidArgumentError` and send appropriate HTTP responses (e.g., 400 Bad Request).","message":"By default, validation failures trigger a `restify.errors.InvalidArgumentError`. Applications must implement appropriate error handling middleware in Restify to gracefully catch and respond to these validation errors, rather than letting them crash the server or return generic 500s.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure `const server = restify.createServer();` is called before any `server.use()` statements.","cause":"The `restify` server instance has not been properly created before attempting to attach middleware.","error":"TypeError: server.use is not a function"},{"fix":"Verify that the client request includes all required fields as defined in the route's `validation` object. Check the exact field name and location (resources, queries, content, headers).","cause":"A request parameter (path, query, body, or header) marked as `isRequired: true` in the validation schema was missing from the incoming request.","error":"Error: InvalidArgumentError: Resource 'name' is required but was not found."},{"fix":"Add `const restify = require('restify');` to your file before using the `restify` variable.","cause":"The `restify` module was not imported or required at the top of the file.","error":"ReferenceError: restify is not defined"},{"fix":"Ensure `const restifyValidation = require('node-restify-validation');` is correctly placed and executed.","cause":"The `node-restify-validation` module was not correctly imported or `require`d, leading to `restifyValidation` being `undefined`.","error":"TypeError: Cannot read properties of undefined (reading 'validationPlugin')"}],"ecosystem":"npm"}