A Railway reference like ${{ Postgres.DATABASE_URL }} reads as a pointer, something that goes and fetches the value later. It doesn't. Railway resolves it during the build, and from then on the variable holds the actual connection string, password included.
That's harmless for a variable your server code reads. It stops being harmless the moment the name starts with VITE_.

Reading the diagram
Top: the variable you wrote. In the Railway dashboard it's one line, VITE_DATABASE_URL pointing at the Postgres service's DATABASE_URL. Nothing on that screen shows a password, which is exactly why it doesn't feel dangerous.
The first arrow: a pointer, for the last time. Railway supplies variables to the build process as well as the running deployment. It resolves the reference at that point, so the build gets the real value.
Left, green: the same value without the prefix. Named DATABASE_URL, it sits in process.env and only your server code reads it at runtime. A visitor never sees it. That's the setup you want for anything secret.
Right: the VITE_ name. Vite treats that prefix as a promise that the value is safe to publish, and it keeps the promise literally. Every import.meta.env.VITE_DATABASE_URL in your code is replaced with the resolved string.
Bottom, the red edges: the bundle and the browser. The output under dist/assets/ now contains postgresql://postgres: followed by the password, as plain text. That file is downloaded with the page, so every visitor has a copy, and there's no login in front of a JavaScript file. These are the only emphasised edges because this is where a server-side secret becomes a public one.
NEXT_PUBLIC_ and SvelteKit's PUBLIC_ work the same way. The diagram uses Vite because its prefix is the one AI tools reach for most in a Railway frontend, but any build-time public prefix inlines the resolved reference.
What to do with it
Search your built output for the password or postgresql:// before you assume you're fine. If it's there, rotate the password first, then rename the variable without the prefix and put the database call behind your own API. The full walkthrough, with every reference form and the built-in RAILWAY_ variables, is in Railway Reference Variables and RAILWAY_PUBLIC_DOMAIN.
The Mermaid source
Copy this and swap in your own variable name.
---
title: "The reference stops being a pointer at build"
---
flowchart TB
D["Railway variable<br/><code>VITE_DATABASE_URL</code><br/><code>${{ Postgres.DATABASE_URL }}</code>"]
B["Build<br/>Railway resolves the reference"]
S["Server code<br/><code>process.env</code> at runtime"]
V["Vite<br/>swaps in every <code>VITE_</code> value"]
J["<code>dist/assets/index.js</code><br/>postgresql://postgres:hT7n...@...:6543"]
X["Every visitor's browser"]
D -->|"a pointer"| B
B -->|"named DATABASE_URL:<br/>stays on the server"| S
B -->|"named VITE_:<br/>the real password"| V
V -->|"<b>written in as a string</b>"| J
J -->|"downloaded with the page"| X
classDef private fill:#ecfdf5,stroke:#10b981,stroke-width:2px,color:#1c1917
classDef public fill:#fef2f2,stroke:#ef4444,stroke-width:2px,color:#1c1917
classDef store fill:#f5f5f4,stroke:#57534e,stroke-width:2px,color:#1c1917
class D,B,V store
class S private
class J,X public
linkStyle 3 stroke:#ef4444,stroke-width:3px
linkStyle 4 stroke:#ef4444,stroke-width:3px
Does a Railway reference variable stay a reference after deploy?
No. Railway resolves the ${{ }} expression before your code sees it, and it supplies variables to the build as well as the running service. By the time anything reads the variable, it holds the real value.
Why does VITE_DATABASE_URL end up in my JavaScript?
Vite replaces every import.meta.env.VITE_ reference with its value while it builds, so the value becomes a string literal in the files under dist/assets. Anything with that prefix is treated as safe to publish, whatever it contains.
How do I check whether my bundle has my database URL in it?
Run your build locally and search the output, for example grep -ri postgresql:// dist/. On a live site, open the browser's developer tools and search the loaded JavaScript files for postgresql or for the first characters of the password.
What should I do if the database URL is already in a deployed bundle?
Rotate the database password first, because anyone who loaded the page could have copied it. Then rename the variable without the VITE_ prefix and move the database call behind your own API.
Is your database URL in your bundle?
A scan reads your live site the way a visitor would and flags database URLs and keys it finds in the JavaScript.