Skip to main content
shorturlx-cli is an official npm package that lets you create shortened URLs directly from your terminal without opening a browser.

Installation and first use

1

Install the CLI globally

Run the following command to install shorturlx-cli globally on your machine:
npm install -g shorturlx-cli
2

Get your API key

Sign in to your ShortURLx account and generate an API key from the API Key Management section of your dashboard.
An API key is required to use custom slugs. You can shorten URLs without one, but you will be subject to lower rate limits.
3

Shorten your first URL

Run the command below, replacing YOUR_API_KEY with your actual key:
shorturlx --url "https://example.com/long-url" --api-key "YOUR_API_KEY"
You will see output like this:
Short URL: https://www.shorturlx.xyz/abcd123
Original URL: https://example.com/long-url
Created at: 6/25/2023, 3:32:48 PM
Short URL copied to clipboard!

Options

OptionAliasDescription
--url-uURL to shorten (required)
--custom-cCustom slug (optional, requires API key)
--api-key-kAPI key (or use SHORTURL_API_KEY env var)
--endpoint-eCustom API endpoint (defaults to www.shorturlx.xyz)
--copy-cpCopy result to clipboard (defaults to true)
--helpShow help

API key configuration

You can provide your API key in two ways:
  • Flag: pass --api-key or -k with each command
  • Environment variable: set SHORTURL_API_KEY once and omit the flag entirely
Using the SHORTURL_API_KEY environment variable keeps your key out of your shell history and process listings.
To set the environment variable, run the command for your operating system:
echo 'export SHORTURL_API_KEY="YOUR_API_KEY"' >> ~/.bash_profile
# or for zsh users:
echo 'export SHORTURL_API_KEY="YOUR_API_KEY"' >> ~/.zshrc
After setting the variable, you can shorten URLs without the --api-key flag:
shorturlx --url "https://example.com/long-url"

Examples

Basic usage:
shorturlx --url "https://example.com/long-url" --api-key "YOUR_API_KEY"
With a custom slug:
shorturlx --url "https://example.com/long-url" --custom "my-slug" --api-key "YOUR_API_KEY"
Custom slugs require a valid API key. If you omit --api-key and SHORTURL_API_KEY is not set, the --custom flag will be ignored.
With a custom API endpoint:
shorturlx --url "https://example.com/long-url" --endpoint "https://your-custom-instance.com/api/shorten"

Build docs developers (and LLMs) love