1

I am learning about node.js, but I think the guide that I was following was slightly outdated. It seems that the "url.parse" method has been deprecated and even through google searches I could not understand which is the appropriate replacement for it, and how to apply it to my code:

const http = require('http'),
  fs = require('fs'),
  url = require('url');

http.createServer((request, response) => {
  let addr = request.url,
    q = url.parse(addr, true),
    filePath = '';

All help is appreciate it!

3
  • 1
    Does this answer your question? node legacy url.parse deprecated, what to use instead? Commented Jul 20, 2021 at 15:24
  • I saw that while looking up for a solution, I guess I just dont understand how to apply it to my code for it to work. Commented Jul 20, 2021 at 15:38
  • 1
    instead of using url.parse, create a new URL object Commented Jul 20, 2021 at 15:39

1 Answer 1

0

You can use the newURL() API. More about this can be found here https://nodejs.org/dist/latest-v8.x/docs/api/url.html#url_the_whatwg_url_api

In the given code snippet, it can be used as follows:

const http = require('http'),
fs = require('fs'),
const { url } = require('url');

http.createServer((request, response) => {
  let addr = request.url,
  q = new url(addr),
  filePath = '';
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.