// Import 'url' and 'querystring' modules
const url = require('url');
const querystring = require('querystring');
// Example request URL
const requestUrl = 'http://example.com/api?param1=value1¶m2=value2';
// Parse the URL
const parsedUrl = url.parse(requestUrl);
// Parse and retrieve query parameters
const queryParams = querystring.parse(parsedUrl.query);
// Log the parsed query parameters
console.log('Query Parameters:', queryParams);Parse URL and Query Parameters
Related Posts
More content you might like
Build a Custom Rate Limiter in Node.js with Redis
// redisClient.js
const redis = require("redis");
const client = redis.createClient({ url: process.env.REDIS_URL });
client.on("error", (err) => console.error("Redis error:", err));
client.connect();
module.exports = client;// rateLimiter.js
const client = require("./redisClient");
const rateLimiter = (limit = 100, windowSec = 3600) => {
return async (req, res, next) => {
const ip = req.ip;
const key = `rate_limit:${ip}`;
const current = await client.get(key);
if (current !== null && parseInt(current) >= limit) {
return res.status(429).json({ error: "Too many requests. Try later." });
}
const multi = client.multi();
multi.incr(key);
if (!current) {
multi.expire(key, windowSec);
}
await multi.exec();
next();
};
};
module.exports = rateLimiter;Building a Real-Time Chat Application with WebSockets in Node.js
WebSockets provide a full-duplex communication channel over a single TCP connection, allowing both the client and server to send messages at any time. Unlike HTTP, WebSockets maintain a persistent connection, making them ideal for applications requiring real-time updates, such as chat apps, online gaming, and live notifications.
If you haven’t already installed Node.js, you can download it from the official website. Node.js includes npm, the package manager we will use to install dependencies.
JWT Token Creation and Verification in Node.js using 'jsonwebtoken'
No preview available for this content.
Simple HTTP Server in Node.js
No preview available for this content.
Discussion 0
Please sign in to join the discussion.
No comments yet. Be the first to share your thoughts!