query-param-extractor
v1.0.3
Published
URL Query Parameter Parser
Downloads
11
Readme
query-param-extractor
query-param-extractor
is a lightweight, easy-to-use npm package designed for extracting query parameters from URLs in Node.js applications. This package provides a straightforward way to parse query strings into JavaScript objects, making it easier to access and manipulate query parameters in your web applications.
Features
- Simple and easy to parse URL query parameters
- Converts query strings to JavaScript objects
- Supports decoding of URL-encoded characters
Installation
To use query-param-extractor
in your project, run the following command in your terminal:
npm install query-param-extractor
Usage
After installation, you can require and use query-param-extractor
in your Node.js files to extract query parameters from URLs. Here's a basic example:
const parseUrlParams = require("query-param-extractor");
const url = "http://example.com?page=2&sort=ascending";
const params = parseUrlParams(url);
console.log(params);
Output:
{ "page": "2", "sort": "ascending" }
Example: Using with Express.js
If you're working with Express.js or a similar web framework, you can use query-param-extractor
to parse query parameters from request URLs:
const express = require("express");
const parseUrlParams = require("query-param-extractor");
const app = express();
app.get("/example", (req, res) => {
const params = parseUrlParams(req.url);
res.json(params);
});
app.listen(3000, () => console.log("Server running on port 3000"));
License
query-param-extractor
is released under the MIT License. See the LICENSE file for more details.