@burmajs/url-parser
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Parse req.url of http.IncomingMessage

Install

npm i @burmajs/url-parser
pnpm i @burmajs/url-parser

Example

ESM

import http from "node:http";
import urlParser from "@burmajs/url-parser";

http
  .createServer(function (req, res) {
    const parseedUrl = urlParser(req);
    if (req.url === "/foo/bar?user=foo&pass=bar") {
      res.writeHead(200, { "Content-Type": "application/json" });
      res.end(
        JSON.stringify({
          parseedUrl,
          user: parseedUrl.getParam("user"),
        })
      );
    }
  })
  .listen(3000);

/*
  {
  "parseedUrl": {
    "pathname": "/foo/bar",
    "query": {
      "user": "foo",
      "pass": "bar"
    },
    "rawUrl": "/foo/bar?user=foo&pass=bar",
    "search": "user=foo&pass=bar"
  },
  "user": "foo"
   }
*/

Common Js

const http = require("node:http");
const urlParser = require("@burmajs/url-parser");

http
  .createServer(function (req, res) {
    const parseedUrl = urlParser(req);
    if (req.url === "/foo/bar?user=foo&pass=bar") {
      res.writeHead(200, { "Content-Type": "application/json" });
      res.end(
        JSON.stringify({
          parseedUrl,
          user: parseedUrl.getParam("user"),
        })
      );
    }
  })
  .listen(3000);

/*
  {
  "parseedUrl": {
    "pathname": "/foo/bar",
    "query": {
      "user": "foo",
      "pass": "bar"
    },
    "rawUrl": "/foo/bar?user=foo&pass=bar",
    "search": "user=foo&pass=bar"
  },
  "user": "foo"
   }
*/

Readme

Keywords

none

Package Sidebar

Install

npm i @burmajs/url-parser

Weekly Downloads

14

Version

1.0.2

License

Apache-2.0

Unpacked Size

15.8 kB

Total Files

6

Last publish

Collaborators

  • phothin