Welcome to the Linux Foundation Forum!

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

Creating. a web server with node core

  1. const server = http.createServer((req, res) => {
  2. res.setHeader('Content-Type', 'text/html')
  3. if (req.method !== 'GET') {
  4. res.statusCode = 405
  5. res.end(STATUS_CODES[res.statusCode] + '\r\n')
  6. return
  7. }
  8. const { pathname } = url.parse(req.url)
  9. if (pathname === '/') {
  10. res.end(root)
  11. return
  12. }
  13. if (pathname === '/hello') {
  14. res.end(hello)
  15. return
  16. }
  17. res.statusCode = 404
  18. res.end(STATUS_CODES[res.statusCode] + '\r\n')
  19. })

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?
**

Answers

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training