# Why does my app work on localhost but not online?

URL: https://antideploy.com/blog/why-does-my-app-work-on-localhost-but-not-online

Your computer and a server are different machines. Nine things usually differ, and each one has a quick check.

## At a glance

- **Your machine**: Your files, your settings, your database
- **A clean server**: Only what you send, plus what it is given
- **Nine usual causes**: Each with a quick check
- **Most fixes are small**: One line, one variable, one file

Published 7 October 2026. Facts checked 7 October 2026. 4 min read.

## The short answer

Localhost is your own computer. It has your files, your `.env` settings, your database and your installed tools. A server starts clean and has only what you send it. When an app works on localhost and fails online, something your computer had is missing on the server.

The fastest way to find it is to read the failure reason and the logs. The nine causes below cover most cases.

## The nine usual causes

### 1. The code still points at localhost

A line such as `fetch("http://localhost:3001/api")` works on your computer and nowhere else, because on a server `localhost` means the server itself. **Check:** search your code for `localhost` and `127.0.0.1`. **Fix:** use a relative path such as `/api`, or read the address from an environment variable.

### 2. The app listens on the wrong port or the wrong address

The platform tells your app which port to use in the `PORT` environment variable, and it must listen on `0.0.0.0`, not `127.0.0.1`. **Check:** the deploy says "built successfully but never started listening". **Fix:** read the port from `PORT` and bind to `0.0.0.0`. See [the full fix](https://antideploy.com/blog/your-app-built-successfully-but-never-started-listening-on-its-port).

### 3. An environment variable is missing

Your `.env` file is on your computer. The server only has the variables you set for it. **Check:** the logs mention `undefined`, or a key is "missing". **Fix:** set the variable, then redeploy. See [environment variables](https://antideploy.com/blog/how-to-set-environment-variables-and-secrets).

### 4. The database only exists on your laptop

A `DATABASE_URL` that points to `localhost` cannot work online. **Check:** look for it in your `.env`. **Fix:** use a hosted Postgres database. Antideploy creates one for your app and sets `DATABASE_URL` for you. See [add a database](https://antideploy.com/blog/how-to-add-a-postgres-database-to-your-app).

### 5. Files saved to disk disappear

Anything your app writes to its own disk is gone on the next deploy. That includes uploads and a SQLite database file. **Check:** search for `multer`, `fs.writeFile` or `sqlite`. **Fix:** use a database for data and a bucket for files. See [file uploads](https://antideploy.com/blog/how-to-add-file-uploads-to-your-app).

### 6. A package is installed on your machine but not in package.json

Your computer may have a tool installed globally, or a lock file that is out of date. The server installs only what the manifest and lock file say. **Check:** the build says a command is "not found", or that `package-lock.json` does not match. **Fix:** add the package and commit the lock file. See [the lock file error](https://antideploy.com/blog/npm-ci-can-only-install-packages-when-package-json-and-package-lock-json-are-in-sync).

### 7. It only works in development mode

`next dev` and `vite dev` are forgiving. A real build is strict: type errors fail it, and code that runs at import time can break it. **Check:** run the production build on your machine, for example `npm run build`. **Fix:** fix what the build reports.

### 8. A file name has a different capital letter

Windows and macOS usually ignore capital letters in file names. Linux servers do not. `Button.tsx` and `button.tsx` are different files there. **Check:** the build says "Module not found". **Fix:** make the import match the file name exactly.

### 9. A timer inside the app never fires

A scheduler such as `node-cron` needs the app to be running, and an idle app sleeps. **Check:** a nightly job never ran. **Fix:** move the work into a route and use a scheduled job that calls it. See [scheduled jobs](https://antideploy.com/blog/how-to-run-a-scheduled-job-on-your-app).

## How to find out which one

1. **Read the failure reason.** Every failed deploy records one sentence that names the cause.
2. **Read the logs.** They show what the app printed before it stopped.
3. **Match the message.** The Fix an error section of this blog has a page for each common message.

Your coding agent can do all three. Say "the deploy failed, read the reason and the logs and fix it". See [how your agent reads logs and fixes a failed deploy](https://antideploy.com/blog/how-to-let-your-coding-agent-read-logs-and-fix-a-failed-deploy).

## Here's where it stops.

A platform that only tells you what it is good at is one you find the edges of in production. These are the ones to know before your first deploy.

### The disk forgets

Anything written to local disk is gone on the next deploy. Apps that speak S3 get a bucket instead.

### Apps sleep when idle

On every plan, an app nobody is using goes to sleep and the next visit wakes it. The first request took 2.9 to 13.9 seconds in our measurements, depending on the stack. There are no always-on workers, so use a cron job or a webhook for background work.

### No background workers

Only the web process runs. A queue consumer or a loop inside the app will not stay alive. Use a cron job to call a path on a schedule, or a webhook.

## Localhost questions, answered.

Anything else? Write to us and a person answers.

[support@antideploy.com](mailto:support@antideploy.com)

### Is this a problem with my code or with Antideploy?

Usually the code, or a setting the server does not have. When the cause is on Antideploy's side, the failure reason says so, and Antideploy builds the same version again for you at no cost.

### Why did it work on Vercel or another host?

Hosts differ in what they install and tolerate. A strict install, such as one that refuses an out-of-date lock file, fails where a forgiving one passes. The reason on the failed deploy tells you which it is.

### Can I test the server setup on my own computer?

Partly. Run the production build and start command locally, with the same environment variables. If that fails, the server will too.

### Does a failed deploy cost anything?

No. Failed deploys never count against your plan.

## More guides, and the platform.

Each platform page covers one part of Antideploy: what it does, where it stops and the questions people ask. [See the whole platform](https://antideploy.com/platform), or [all the guides](https://antideploy.com/blog).

- [How to let your agent read logs and fix a failed deploy](https://antideploy.com/blog/how-to-let-your-coding-agent-read-logs-and-fix-a-failed-deploy): The loop: read the reason, read the logs, fix the code, deploy again. And what Antideploy repairs for you.
- [Your app built successfully but never started listening on its port](https://antideploy.com/blog/your-app-built-successfully-but-never-started-listening-on-its-port): The app built but never answered on its port. Read PORT, listen on 0.0.0.0 and check the logs.
- [What does deploying an app mean?](https://antideploy.com/blog/what-does-deploying-an-app-mean): Deploying, in plain words. The ten words you will meet, and what each one means.

- [Environment variables](https://antideploy.com/platform/environment-variables)
- [Database](https://antideploy.com/platform/database)
- [File storage](https://antideploy.com/platform/file-storage)
- [Logs and monitoring](https://antideploy.com/platform/logs-and-monitoring)
- [Deployments](https://antideploy.com/platform/deployments)

Facts on this page were checked against the live platform on 7 October 2026.

## Deploy something. Start with one sentence.

Paste one sentence into your coding agent, click Approve once, and get a live link. No card, no trial clock.

To set this up, give your coding agent this sentence:

```text
Set this project up to deploy on Antideploy. Fetch https://antideploy.com/agent.md and follow it.
```
