Registry / web-framework / node-restify-validation

node-restify-validation

JSON →
library1.3.0jsnpmunverified

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.

npm install node-restify-validation
INSTALL
IMPORT
SIG · NODE-RESTIFY-VALID
N
node-restify-validation
web-frameworkjavascriptv1.3.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

validationPlugin
const restifyValidation = require('node-restify-validation'); // then use restifyValidation.validationPlugin
import { validationPlugin } from 'node-restify-validation';
This library is written for CommonJS (`require`) environments. Direct ESM `import` statements may not work without transpilation or specific Node.js configuration.
validation route property
server.get({ url: '/test', validation: { ... } }, handler)
Validation rules are defined directly as a `validation` property within the route object passed to Restify methods like `server.get`, `server.post`, etc.

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.

const restify = require('restify'); const restifyValidation = require('node-restify-validation'); const server = restify.createServer(); server.use(restify.queryParser()); server.use(restify.bodyParser()); // Required for 'content' validation server.use(restifyValidation.validationPlugin({ errorsAsArray: false, forbidUndefinedVariables: false, errorHandler: restify.errors.InvalidArgumentError })); server.get({ url: '/test/:name', validation: { resources: { // Path parameters name: { isRequired: true, isIn: ['foo', 'bar'] } }, queries: { // Query parameters status: { isRequired: true, isIn: ['foo', 'bar'] }, email: { isRequired: false, isEmail: true }, age: { isRequired: true, isNatural: true } }, headers: { // HTTP Headers requestid: { isRequired: true } } } }, function (req, res, next) { res.send(200, { message: `Hello ${req.params.name}, your status is ${req.query.status}.` }); return next(); }); server.listen(8001, function () { console.log('%s listening at %s', server.name, server.url); });
Debug
Known issues
breakingThe 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.
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.
affects: >=1.0.0
gotchaThis 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.
fix
Ensure that your project's `package.json` specifies a `restify` dependency of version `2.6.0` or higher.
affects: <1.0.0 (of node-restify-validation used with restify < 2.6.0)
gotchaThe 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.
fix
Always use `const restifyValidation = require('node-restify-validation');` for importing the module in your Node.js applications.
affects: All versions
gotchaBy 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.
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).
affects: All versions
Errors
Common errors & fixes
TypeError: server.use is not a function
The `restify` server instance has not been properly created before attempting to attach middleware.
fix
Ensure `const server = restify.createServer();` is called before any `server.use()` statements.
Error: InvalidArgumentError: Resource 'name' is required but was not found.
A request parameter (path, query, body, or header) marked as `isRequired: true` in the validation schema was missing from the incoming request.
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).
ReferenceError: restify is not defined
The `restify` module was not imported or required at the top of the file.
fix
Add `const restify = require('restify');` to your file before using the `restify` variable.
TypeError: Cannot read properties of undefined (reading 'validationPlugin')
The `node-restify-validation` module was not correctly imported or `require`d, leading to `restifyValidation` being `undefined`.
fix
Ensure `const restifyValidation = require('node-restify-validation');` is correctly placed and executed.
Upgrade
Version history
1.3.0latest on npm
Audit
Dependencies
restifyrequiredCore dependency for building REST services that this library validates. Requires restify >= 2.6.0.
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
node-restify-validation — npm install node-restify-validation · libregistry