Connect Querystring Middleware

1.0.3 · abandoned · verified Wed Apr 22

The `qs-middleware` package provides a Connect-compatible middleware designed for parsing URL querystrings and populating the `request.query` property. It integrates with the widely used `qs` module for robust querystring parsing, allowing users to pass configuration options directly to `qs` (e.g., `allowDots`, `arrayLimit`). Currently at version 1.0.3, the project appears to be unmaintained, with its last significant code activity dating back to 2016. Its primary function is to abstract the direct interaction with `qs` for traditional Connect and Express applications, making it straightforward to access parsed query parameters. Given its age, it primarily supports CommonJS environments and older Node.js versions, lacking native ES Module support.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up `qs-middleware` with a basic Connect server to automatically parse URL querystrings into `request.query`. It shows how to pass options to the underlying `qs` module and confirms how the parsed query is accessible and returned in the HTTP response.

const http = require('http');
const connect = require('connect');
const query = require('qs-middleware');

const app = connect();

// Create a simple Connect application that uses qs-middleware
// Pass options directly to the underlying 'qs' module, e.g., allowDots
app.use(query({ allowDots: true, depth: 5 })); 

app.use(function(request, response) {
    console.log('Parsed Query:', request.query);
    response.setHeader('Content-Type', 'application/json');
    response.end(JSON.stringify({
        message: 'Query parsed successfully!',
        query: request.query,
        example_urls: [
            'http://localhost:3000/?name=Alice&age=30',
            'http://localhost:3000/?user.name=Bob&items[0]=apple&items[1]=orange&foo=bar&nested[a][b][c]=d'
        ]
    }, null, 2));
});

const server = http.createServer(app);
server.listen(3000, () => {
    console.log('Connect app with qs-middleware running on http://localhost:3000');
    console.log('Try visiting: http://localhost:3000/?name=Alice&age=30');
    console.log('Or with qs options in effect: http://localhost:3000/?user.name=Bob&items[0]=apple&items[1]=orange');
});

view raw JSON →