Open your hosting company

Enzonic for Resellers

Open your hosting company

How to host a Node.js app or bot for your community

Run a Node.js bot, API or worker on a panel: package.json and lockfile, ports, environment secrets, graceful shutdown, logs, updates and memory.

Enzonic teamUpdated 6 minute read

Communities run on small programs. A Telegram bot that welcomes new members, a webhook listener that announces new store orders, a little API that powers the leaderboard on your website, a worker that checks whether your game server is up and posts in chat when it is not. If yours are written in Node.js, they all have the same needs once they leave your laptop: install cleanly, start on their own, keep secrets secret, listen on the right port, shut down properly and leave useful logs.

This guide covers running a general Node.js app for your own community or project on a hosting panel. For Discord bots specifically, intents and slash commands add their own steps, covered in how to host a discord.js bot for your community.

What you are setting up

On a game-style hosting panel, your app runs as one long-lived process in a container with limits for memory, CPU and disk. The panel starts it, shows its output in a console and lets you stop, start and restart it. There is no build pipeline unless you make one, so the files you upload are what runs.

Pick a Node.js version first. Use a current LTS release from nodejs.org unless a dependency forces something else, and develop on the same major version you run on the server.

A clean project layout

community-app/
  package.json
  package-lock.json
  .env.example        (names of the variables, no real values)
  .env                (real values, never committed)
  src/
    index.js          (entry point)
    routes/
    jobs/
  data/               (SQLite or JSON storage)

Keep .env.example in your repository with empty values. It documents which variables the app needs, so whoever deploys it next (including you in six months) knows what to fill in.

package.json and the lockfile

package.json is the install recipe and the start command:

{
  "name": "community-app",
  "private": true,
  "type": "module",
  "main": "src/index.js",
  "scripts": {
    "start": "node --env-file=.env src/index.js"
  },
  "engines": {
    "node": ">=20.6"
  },
  "dependencies": {
    "express": "^4.19.0"
  }
}

Points worth knowing:

  • **"type": "module"** makes .js files ES modules (import/export). Without it, Node.js treats them as CommonJS (require). Mixing the two styles is the source of the classic "Cannot use import statement outside a module" error. Pick one and stay consistent.
  • The lockfile pins exact dependency versions. Commit it, and install on the server with npm ci, which installs exactly what the lockfile says and fails loudly if it does not match package.json.
  • **Do not upload node_modules.** Install on the server. Packages with native code are compiled for your machine and may not load on Linux.
  • **--env-file** is built into Node.js since version 20.6, so a small app no longer needs the dotenv package to load a .env file. On older versions, use dotenv.

Environment variables and secrets

Everything secret goes into environment variables: bot tokens, API keys, database passwords, webhook signing secrets. Read them once at startup and fail fast if one is missing:

const required = ['TELEGRAM_TOKEN', 'WEBHOOK_SECRET'];
for (const name of required) {
  if (!process.env[name]) {
    console.error(`Missing environment variable ${name}`);
    process.exit(1);
  }
}

Failing fast is kinder than failing later. An app that starts without its token and crashes on the first message is harder to diagnose than one that refuses to start with a clear line in the console.

Rules that keep secrets safe on a shared panel:

  1. Never commit .env. Add it to .gitignore before the first commit, not after.
  2. Never paste secrets into chat when asking for help. Share the error, not the config.
  3. Give helpers their own panel access instead of sending them the file.
  4. If something leaks, rotate the secret at its source first, then update the server.

Listening on the right port

If your app receives traffic (an API, a webhook, a dashboard), it must listen on the port the panel allocated to the server and on all interfaces, not just localhost:

import express from 'express';

const app = express();
const port = Number(process.env.SERVER_PORT || process.env.PORT || 3000);

app.get('/health', (req, res) => res.send('ok'));

app.listen(port, '0.0.0.0', () => {
  console.log(`Listening on ${port}`);
});

Check which environment variable your panel provides for the allocated port, or set your own variable to the port number shown in the panel's network section. A hard-coded port that does not match the allocation is the most common reason a hosted app "runs but cannot be reached."

Apps that only make outgoing connections (a Telegram bot in polling mode, a worker that calls APIs) do not need an inbound port at all.

Graceful shutdown

When you press stop or restart, the process is asked to exit, typically with a SIGTERM signal. If it ignores the signal, it will eventually be killed, possibly in the middle of writing a file. Handle the signal so the app finishes what it is doing:

const server = app.listen(port, '0.0.0.0');

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

If you use SQLite or write JSON files, close the database or flush the file in the same handler. This is the difference between a clean restart and a corrupted data file once a month.

Crash loops and restarts

A crash loop is a process that dies during startup again and again. For Node.js apps the usual causes are a missing environment variable, a module that did not install, the ES modules versus CommonJS mismatch, or a port already in use because two copies are running.

When it happens: stop the server, read the first error after startup and fix that one. Do not keep pressing restart. Inside the app, catch errors in request handlers and scheduled jobs so that one bad input does not take the whole process down, and log unhandled promise rejections so they are visible.

Logs

Your console is your log: everything written to standard output and standard error appears there. Some practical rules:

  • One line on startup with the version and port.
  • One line per error, with enough context to find it (the route, the job name, an ID).
  • No secrets, no full request bodies, no private messages.

If you also write logs to files, rotate them or delete old ones on a schedule. A log folder that grows forever will eventually fill the disk and stop the app.

Memory limits

The container has a fixed memory limit. Node.js sets its own heap size, which may not match your plan, so tell it explicitly. For example, on a plan with 512 MB, something like node --max-old-space-size=384 src/index.js keeps the heap under the limit with room for everything else the process uses. Treat that ratio as a starting point.

If memory climbs steadily and never drops, look for things that only grow: caches without a size cap, arrays of past events, listeners added on every request.

Updating safely

  1. Back up the server and your data folder first.
  2. Upload changed files.
  3. Run npm ci if the lockfile changed.
  4. Restart and watch the console for the startup line.

Update dependencies on purpose, not by accident. Run npm outdated at home, upgrade, test, then deploy the new lockfile.

Running it through a branded panel with Enzonic for Resellers

If you manage several apps, bots and game servers for a community, Enzonic for Resellers gives you your own branded panel for all of them. Opening a site is free, and panel-only mode serves only sign-in and the customer panel, with no storefront.

The panel includes a live console with power controls and CPU, memory and disk stats, a file manager and SFTP, backups and scheduled backups, scheduled tasks, subusers for co-admins and network ports for apps that receive traffic. With Enzonic for Resellers, Node.js apps runs on Enzonic nodes in Europe, North America and Asia and on your own Pterodactyl or Pelican Wings nodes, so you can sell it without running any hardware. You can also connect your own Pterodactyl Wings or Pelican Wings machine. Servers you grant on Enzonic nodes have their base price charged monthly from your credits.

If part of your stack is in another language, see the guides for Python, Go and Java. Open a site to try it.

Frequently asked questions

Why can I not reach my Node.js app after it starts?

It is probably listening on a different port than the one allocated, or only on localhost. Bind to 0.0.0.0 and read the port from an environment variable that matches the panel's allocation.

Should I use npm install or npm ci on the server?

Use npm ci with a committed lockfile. It installs exactly the versions you tested and fails clearly if the lockfile is out of date.

Do I need pm2 or nodemon on a panel?

Usually not. The panel already starts and stops the process and shows its output. Tools that restart on file changes are meant for development and can hide crash loops on a server.

How do I run two Node.js apps for my community?

Give each its own server. Separate servers keep memory limits, logs and restarts independent, so one broken app cannot take the other down.

#nodejs#javascript#bots#app-hosting