Skip to content

DocsRun your app

The running app

What every app gets and has to do while it runs: the port and address to listen on, the variables set for you, no root rights, a temporary disk, the stop signal.

Whatever the framework, an app on the platform is a Node.js process in a replica. This page says what that process gets and what it has to do. The guide of your framework says how to do it in its idiom.

The platform sets the PORT variable and sends every request to that port. It is 3000 unless you change it under Settings, Build & deploy.

  • Read the port from PORT. A port written into the code only works by accident.
  • 1024 or higher. Lower ports are not open to an app, and the settings refuse them.
  • Listen on all interfaces. Give no host, or 0.0.0.0. A server on localhost or 127.0.0.1 cannot be reached, and the deployment fails with “nothing listens on port N, so make sure the app listens on 0.0.0.0:N, not only on 127.0.0.1”.
  • One port. Only this port gets traffic. A second server on another port is not reachable.
  • Plain HTTP. HTTPS is handled before a request reaches your app. Do not load certificates in the app. See Requests and sockets.

A React, Vue or Angular app, and any other app the platform serves as built files, has nothing to do here: the platform’s own server listens for it.

The new version has 2 minutes to start listening, or, with a health check path, the wait you set there to answer on that path. If it takes longer, the deployment fails and the old version stays.

Do slow one-off work before the app starts, not inside it. Database migrations belong in deploy commands.

Variable Value
PORT The port from the build settings
NODE_ENV production, for the build and for the running app

You cannot change or remove them. APP_URL is not set for you: if your code reads it, add it under Settings, Variables with the address you want, and change it yourself when the address changes. Names that start with PLATFORM_ are kept for the platform as well. Some frameworks get a few more, named in their guide (AdonisJS and Astro). Everything else comes from the environment variables you add.

The app runs as a user without root rights, and so do the deploy commands and cron jobs. The install and the build run with full rights.

  • Files. The app can write in its own folder, in its home folder and in /tmp. Writing anywhere else fails with “permission denied” or EACCES.
  • Ports. A port below 1024 cannot be used.
  • System packages. Nothing can be installed while the app runs. Only the npm packages in your package.json are there.

The disk of a replica is temporary. A file written while the app runs is gone after the next deployment or restart, and it can be gone after the app has slept. Replicas do not share files.

  • Database. Use a hosted database and put its address in a variable, DATABASE_URL for example. SQLite in a file does not survive.
  • Uploads. Send them to a file store outside the app, not to a folder.
  • Logs. Print to the console. A log written to a file is on the disk of one replica, where you cannot read it. See Logs and crashes.

Memory is temporary in the same way, and it is not shared between replicas. Sessions, caches, counters and rate limits kept in memory are gone at every deployment and differ between replicas. Keep them in a database or a store outside the app. express-session without a store is the usual case.

An app that uses more memory than its size has is stopped and started again; the runtime log says so.

To stop a replica, the platform sends SIGTERM and waits 30 seconds. Close the server on that signal, so open requests can finish:

process.on('SIGTERM', () => {
server.close(() => process.exit(0));
});

A replica stops at every deployment, at a restart, at a change of scaling and when the app sleeps.

A replica that exits with an error is started again, up to 3 times. After that it is left stopped, the overview says so and the team gets a notification. The last lines before the exit are in the runtime log. See Logs and crashes.

An idle app sleeps and wakes only for a request. A timer, a cron package or a queue worker inside the app does not run while it sleeps, and with more than one replica it runs on every one of them. Keep Keep one replica always on switched on for such an app, or move the work out of the app: a cron job for work on a schedule, a worker for a queue worker or any command that keeps running. See Sleep and wake.