Relative vs Absolute URL Resolution in Node.js
📖 Scenario: You are building a simple Node.js script that helps a web developer understand how URLs combine when given a base URL and a relative path. This is useful when linking pages or resources on websites.
🎯 Goal: Create a Node.js script that uses the URL class to resolve relative URLs against a base absolute URL and print the resolved absolute URLs.
📋 What You'll Learn
Create a base URL string variable with the exact value 'https://example.com/folder/'
Create a relative URL string variable with the exact value '../image.png'
Use the Node.js
URL class to resolve the relative URL against the base URLCreate a variable to hold the resolved absolute URL string
Print the resolved absolute URL string
💡 Why This Matters
🌍 Real World
Web developers often need to combine base URLs with relative paths to link resources correctly on websites or in APIs.
💼 Career
Understanding URL resolution is important for backend and frontend developers to manage links, redirects, and resource loading accurately.
Progress0 / 4 steps