🤖 The Modern AI Developer · After Launch: Keep It Running

How to Deploy an AI-Built App: Hosting, Domains, Secrets

Shortest path: one-click deploy on a hosting platform, domain, environment variables and secrets

一句话先懂 · TL;DR

From runs-on-my-computer to launched: one-click deploys on hosting platforms, connecting a domain, and handling environment variables and secrets safely.

'Runs on My Computer' Isn't 'Launched'

Running on your own computer is just opening a home kitchen: only you stand at the stove, only you get to eat the dish. Launching is taking the dish to a storefront on the street, where anyone passing by can order.

The difference between them is three things: put the program on a public-internet server, set up a domain people can remember, and keep it always on (it can't stop just because you turned off your computer).

🔆The local address localhost (i.e. 127.0.0.1) is a house number that always points to your own computer. When someone types it on their computer, it opens their door, not your store.
💡For beginners, the shortest path to launch is one-click deploy on a hosting platform—don't start by renting a server, installing an OS, and configuring firewalls.

Hosting Platforms: Outsource the Dirty Work of Setting Up Shop

A hosting platform (the kind that "auto-deploys once you connect your code repo") does a pile of dirty work for you: provision the machine, install the runtime, get your code running, and connect the exit to the public internet. You just hand over the code, and it gives you a reachable URL.

The typical flow is just three steps: connect the repo → it auto-builds → it gives you a URL. Change the code and push again, and it auto-redeploys.

# 很多托管平台的部署就这么简单:把代码推上去
git push
# 平台检测到更新 → 自动构建 → 几十秒后给你一个公网网址
# 例如 https://my-cute-app.example.app
💡By default the platform gives you a long, random URL. It works but isn't memorable. Next we'll swap it for your own domain.

Domain and Secrets: The House Number and the Safe

A domain is your store's house number, like purrlearn.com. After you buy it, do a one-time "pointing" setup that tells it "to reach me, go to the hosting platform's machine," and people can enter your store by typing your domain.

A secret (such as the API key for calling an AI model) is your safe key, and must never be hardcoded in the code—code goes into the repo and may be seen by others, leaking the key.

⚠️Writing the secret into the code and pushing it to a public repo is like taping the safe key to the store's front door. The right way is to put it in the platform's environment variables, read at runtime, so the key never enters the code. (Add any .env file containing secrets to .gitignore and never commit it to the repo—this is the most common way beginners leak secrets.)
// 错误:钥匙写死在代码里,跟着代码一起泄露
const apiKey = "sk-1234真实密钥";

// 正确:从环境变量读,密钥配在平台后台,不进代码
const apiKey = process.env.API_KEY;

自测 · 学完检查一下

想真正动手做题、记进度、攒连胜?到互动课里练。

Judge: if the code opens in my local browser, it means it has been successfully launched and others can access it too.

答案:False

Running locally ≠ launched. You must deploy the program to a publicly reachable environment, set up a domain, and keep it running before others can access it.

If someone types `http://localhost:3000` in their own computer's browser, will it open the app you just wrote?

答案:No—localhost always points to the visitor's own computer

localhost (127.0.0.1) means "this machine"; whoever types it points to their own machine, so others can't open your local app.

A complete beginner wants their app online as fast as possible—which path is most recommended?

答案:One-click deploy on a hosting platform

A hosting platform handles the dirty work of provisioning machines, installing the runtime, and connecting to the public internet—the shortest, least error-prone path to launch for beginners.

Judge: on many hosting platforms, the core action of deploying can be simplified to "push the code, and the platform auto-builds and gives you a public URL."

答案:True

The typical platform flow is "connect repo → auto-build → return a reachable URL"; pushing code again auto-redeploys.

Judge: for convenience, writing the API key directly in the code and pushing it to a public repo is no big deal.

答案:False

Code goes into the repo and may be seen by others; hardcoding the key publicizes it. Put it in environment variables and read it at runtime.

Not hardcoding secrets in code, but configuring them in the platform backend and reading them at runtime—what is this mechanism called? (Fill in the term, or its English.)

答案:environment variable

Environment variables (commonly written as process.env.XXX) separate the secret from the code, so the key enters neither the code nor the repo.

想边练边学,而不只是读?

到互动课里答题、记进度、攒连胜——游客即可试学,无需注册。

进入互动课程 →

Learn something new — don't miss updates

New courses, features and learning tips. Occasional emails, unsubscribe anytime.