Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

20-Node.js Modules - url.parse() is DEPRECATED #15

Open
fewdn opened this issue Jan 20, 2025 · 0 comments
Open

20-Node.js Modules - url.parse() is DEPRECATED #15

fewdn opened this issue Jan 20, 2025 · 0 comments

Comments

@fewdn
Copy link

fewdn commented Jan 20, 2025

Chapter 20 url.parse() is deprecated and needs to be updated to use WhatWg URL API.

https://nodejs.org/api/url.html#the-whatwg-url-api
https://url.spec.whatwg.org/

DEPRECATED url.parse() syntax:

  const url = require('url');
  const myUrl = url.parse("https://www.example.com/listing?id=1000&premium=true");
  console.log(myUrl); // the url object
  console.log(`Host: ${myUrl.host}`);  // www.example.com

WhatWg URL API syntax:

// taken from nodejs.org:
// The new URL constructor is accessible as a property of the global object. 
// It can also be imported from the built-in url module.
  const myUrl = new URL("https://www.example.com/listing?id=1000&premium=true");
  console.log(myUrl);  // the url object
  console.log(`Host: ${myUrl.host}`);  // www.example.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant