Welcome to the Linux Foundation Forum!

url.parse Stability: 0 =Deprecated: Use the WHATWG URL API

Creating. a web server with node core

const server = http.createServer((req, res) => {
  res.setHeader('Content-Type', 'text/html')
  if (req.method !== 'GET') {
    res.statusCode = 405
    res.end(STATUS_CODES[res.statusCode] + '\r\n')
  const { pathname } = url.parse(req.url)
  if (pathname === '/') {
  if (pathname === '/hello') {
  res.statusCode = 404
  res.end(STATUS_CODES[res.statusCode] + '\r\n')

The code above is from the section creating a web server with node core. It uses the url.parse method to retrieve the url path. While recreating this serve. I was looking at the documentation and I found this.

url.parse(urlString[, parseQueryString[, slashesDenoteHost]])

Stability: 0 - Deprecated: Use the WHATWG URL API instead.

here: https://nodejs.org/dist/latest-v14.x/docs/api/url.html#url_url_parse_urlstring_parsequerystring_slashesdenotehost

And it is telling me that using this method can introduce security issues.

I tried using the WHATWG URL API that they recommend, Although I found that API to be cumbersome.

**How should we be recreating this server, should we be doing it with the path.url() or is there a another way we might want to do it?


Sign In or Register to comment.