Restify is an opinionated Node.js web service framework optimized for building semantically correct RESTful APIs. Unlike more generalized frameworks like Express, Restify focuses purely on API development, offering built-in features for introspection, performance, DTrace support, and robust error handling. It's designed for high-throughput, scalable services and is utilized in large-scale Node.js deployments. The current stable version is 11.2.0, released in August 2023. Major releases, often introducing breaking changes or significant feature updates, occur periodically, with more frequent minor and patch updates addressing bugs and adding smaller features.
npm install restifyVerified import paths — ran on the pinned version, not inferred.
This quickstart sets up a basic Restify server with GET and POST routes, utilizing common plugins for body and query parsing. It includes basic error handling for unmatched routes and general Restify errors, demonstrating fundamental API building blocks.
Review and update any custom middleware or audit plugins that rely on `req.log` being reset or overridden by Restify's internal mechanisms. Ensure your logger is properly initialized before Restify's `.first` chain if you need it to persist.
Upgrade your Node.js environment to version 18.x or later. Test your application thoroughly against the new Node.js version and Restify 10+.
Migrate your logging configuration from Bunyan to Pino. Replace `restify-bunyan-logger` with `pino` and its Restify integration (e.g., `restify-pino-logger` if you were using an integration layer). Review logs for any format changes.
Instead of `return next('route-name');`, use explicit `res.redirect()` or handle the routing logic within your application, possibly by calling another handler directly or using a custom routing mechanism.Upgrade your Node.js environment to a supported version (e.g., Node.js 14.x, 16.x for v9, and 18.x+ for v10+).
Always ensure `return next();` is called at the end of middleware and route handlers, unless you explicitly intend to terminate the response (e.g., `res.send()` without `next()`, or `next(false)`). When passing an error, use `return next(new restify.errors.InternalServerError('message'));` for consistent error handling.If DTrace is not needed or causing installation problems, install Restify using `npm install restify --no-optional` to skip optional dependencies like `dtrace-provider`.
Uninstall `bunyan` and related Restify Bunyan loggers. Install `pino` and integrate it, possibly using `restify-pino-logger` or configuring Pino directly with `restify.createServer({ log: pinoInstance })`.Replace `return next('route-name');` with `res.redirect('/new-route-path');` or implement custom dispatch logic. If an error is intended, pass an `Error` object to `next()`.Increase the `maxBodySize` option in your `bodyParser` configuration (e.g., `server.use(restify.plugins.bodyParser({ maxBodySize: 1024 * 1024 * 10 }));` for 10MB). This can also be influenced by server-level configurations like Nginx or cloud load balancers.Ensure that every handler either calls `res.send()` to terminate the response or `return next();` (or `return next(err);` for errors) to pass control to the next middleware in the chain. Pay close attention to asynchronous operations within handlers.