How to parse a URL Hostname in JavaScript and Node.js

How to parse a URL Hostname in JavaScript and Node.js

Parsing URLs in JavaScript and Node.js. There are many ways to parse a URL, but I will show how to make it very simple and effective.

There are many ways to do it, but I will show how to make it very simple and effective.

Parsing URLs in JavaScript and Node.js

var parser = new URL('https://morioh.com/p/480aef8e92cd?f=5db7ed114ed9706bfadc8dc9#hash');
console.log(parser);

Result

{
  href: 'https://morioh.com/p/480aef8e92cd?f=5db7ed114ed9706bfadc8dc9#hash',
  origin: 'https://morioh.com',
  protocol: 'https:',
  username: '',
  password: '',
  host: 'morioh.com',
  hostname: 'morioh.com',
  port: '',
  pathname: '/p/480aef8e92cd',
  search: '?f=5db7ed114ed9706bfadc8dc9',
  searchParams: URLSearchParams { 'f' => '5db7ed114ed9706bfadc8dc9' },
  hash: '#hash'
}

It's simple right?

javascript node nodejs

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Node canvas is a Cairo backed Canvas implementation for NodeJS.

node-canvas is a Cairo-backed Canvas implementation for Node.js.

How to Hire Node.js Developers And How Much Does It Cost?

A Guide to Hire Node.js Developers who can help you create fast and efficient web applications. Also, know how much does it cost to hire Node.js Developers.

Hire NodeJs Developer

Looking to build dynamic, extensively featured, and full-fledged web applications? **[Hire NodeJs Developer](https://hourlydeveloper.io/hire-dedicated-node-js-developer/ "Hire NodeJs Developer")** to create a real-time, faster, and scalable...

Node.js for Beginners - Learn Node.js from Scratch (Step by Step)

Node.js for Beginners - Learn Node.js from Scratch (Step by Step) - Learn the basics of Node.js. This Node.js tutorial will guide you step by step so that you will learn basics and theory of every part. Learn to use Node.js like a professional. You’ll learn: Basic Of Node, Modules, NPM In Node, Event, Email, Uploading File, Advance Of Node.

How to get started Internationalization in JavaScript with NodeJS

Tutorial showing how to use the Intl JS API in NodeJS (i18n). We'll install a module to unlock the Intl API languages for Node and test out RelativeTimeFormat to translate and localise relative times in JavaScript.