Skip to main content
URL.prototype.username - node__url.d.ts - Node documentation
property URL.prototype.username

Usage in Deno

```typescript import { URL } from "node:node__url.d.ts"; ```
Gets and sets the username portion of the URL. ```js const myURL = new URL('https://abc:xyz@example.com'); console.log(myURL.username); // Prints abc myURL.username = '123'; console.log(myURL.href); // Prints https://123:xyz@example.com/ ``` Any invalid URL characters appearing in the value assigned the `username` property will be `percent-encoded`. The selection of which characters to percent-encode may vary somewhat from what the [parse](../.././node__url.d.ts/~/parse) and [format](../.././node__url.d.ts/~/format) methods would produce.

Type

string