npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vercel-url

v0.2.1

Published

Utility constant values for getting Vercel Deployment URLs

Downloads

415

Readme

vercel-url

A helper package that determines the Vercel deployment url DEPLOYMENT_URL at build time. Also provides easier access to Vercel system environment variables. Great for replacing APP_URL, NEXT_PUBLIC_URL, or runtime getBaseUrl() functions where applicable.

Installation

npm i vercel-url

or with Bun:

bun i vercel-url

Usage

import { DEPLOYMENT_URL } from "vercel-url";

Features

  • Dynamically sets the URL at build time
  • Can be used both server-side and client-side
  • Provides easier access to Vercel system environment variables

How it works

This package determines the DEPLOYMENT_URL based on the Vercel environment:

  • In production: Uses VERCEL_PROJECT_PRODUCTION_URL
  • In preview: Uses VERCEL_BRANCH_URL if available, otherwise VERCEL_URL
  • In development: Defaults to http://localhost:3000

Caveats

  • Preview builds from branch commits may not work as expected because VERCEL_BRANCH_URL will be present.
  • There's no simple way to detect this at build time, so the package uses the branch URL when present.

Accessible Variables

The package provides easier access to the following Vercel system environment variables:

  • VERCEL_ENV
  • VERCEL_URL
  • VERCEL_BRANCH_URL
  • VERCEL_PROJECT_PRODUCTION_URL

Important Note: These variables are not automatically exposed or leaked when you use this package. They are only accessible if you explicitly import and use them in your code. However, be aware that if your application is bundled (e.g., with Webpack or Rollup), unused exports might still be included in the bundle unless proper tree-shaking is implemented.

Benefits

  1. Dynamic URL setting at build time
  2. Values can be used both server-side and client-side
  3. Seamless integration with Vercel deployments
  4. Use Vercel system env variables directly without process.env

Security Considerations

When using this package, keep in mind:

  1. The DEPLOYMENT_URL is doesn't expose the values used to derive it.
  2. If you only import DEPLOYMENT_URL, the other Vercel environment variables will not be exposed unless explicitly imported.
  3. If you choose to import and use the other variables (VERCEL_ENV, VERCEL_URL, etc.), ensure you're not unintentionally exposing sensitive information, although these variables are generally safe to use.

Additional Information

For more details on Vercel's system environment variables, refer to the official Vercel documentation.

License

MIT