Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ware

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ware

Easily create your own middleware layer.

  • 0.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
147K
decreased by-3.53%
Maintainers
1
Weekly downloads
 
Created

What is ware?

The 'ware' npm package is a middleware engine for handling a series of functions in a pipeline. It allows you to compose middleware functions and execute them in sequence, making it useful for tasks such as request handling, data processing, and more.

What are ware's main functionalities?

Middleware Composition

This feature allows you to compose multiple middleware functions and execute them in sequence. Each middleware function can modify the request and response objects and pass control to the next function in the pipeline.

const ware = require('ware');

const middleware = ware()
  .use((req, res, next) => {
    req.processed = true;
    next();
  })
  .use((req, res, next) => {
    res.message = 'Hello, world!';
    next();
  });

const req = {};
const res = {};

middleware.run(req, res, (err) => {
  if (err) throw err;
  console.log(req.processed); // true
  console.log(res.message); // 'Hello, world!'
});

Error Handling

This feature demonstrates how 'ware' handles errors in the middleware pipeline. If an error is passed to the 'next' function, the subsequent middleware functions are skipped, and the error is handled in the final callback.

const ware = require('ware');

const middleware = ware()
  .use((req, res, next) => {
    next(new Error('Something went wrong'));
  })
  .use((req, res, next) => {
    res.message = 'This will not be executed';
    next();
  });

const req = {};
const res = {};

middleware.run(req, res, (err) => {
  if (err) {
    console.error(err.message); // 'Something went wrong'
  }
});

Other packages similar to ware

Keywords

FAQs

Package last updated on 25 Apr 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc