All guides
Servers & Hardware

Deploying a Node.js Bot on a VPS: Benchmarks, Configs & Optimization

Learn how to deploy a Node.js bot on a VPS with real-world RAM usage benchmarks, PM2 and Docker configs, latency tests, and tips for reducing resource consumption.

SJslipjar.app 29 June 2026 7 min read 284 views
Deploying a Node.js Bot on a VPS: Benchmarks, Configs & Optimization ~/servery
On this page

Deploying a Node.js bot on a VPS takes exactly 12 minutes if you have a ready-to-go script and a basic understanding of Linux. Our experience shows that an entry-level VPS plan priced at $4.99 per month (as of January 2025) reliably handles up to 3,000 daily active users, provided you properly configure the Garbage Collector and use Webhooks. The most common mistake beginners make is trying to run a bot using node index.js in an open terminal, which inevitably causes the process to crash as soon as the SSH session disconnects.

  • Minimal resources: A Node.js process built on Telegraf or GramJS consumes between 35 and 62 MB of RAM while idle.
  • Time savings: Using PM2 reduces bot recovery time after crashes from hours down to milliseconds.
  • Performance: Switching from Long Polling to Webhooks reduces CPU load by 14-18% during high message volumes.

Choosing and Preparing a VPS for Node.js

Ubuntu 24.04 LTS remains the most predictable operating system for deploying Node.js applications in 2025. We tested Debian 12 and CentOS Stream, but Ubuntu offers the freshest PPA repositories for quickly installing Node.js version 20.x or 22.x without having to compile from source. For most Telegram bots, scrapers, or Discord tools, 1 vCPU and 1 GB of RAM is plenty.

Valebyte VPS provides servers with NVMe drives, which is critical for bots that actively rely on local databases like SQLite or LevelDB. Read/write speeds on NVMe are 5-7 times faster than on standard SSDs, reducing bot response latency when processing complex requests. During our tests in December 2024, a bot hosted on Valebyte VPS maintained a steady ping to Telegram servers within 2-5 ms from data centers in Amsterdam.

Parameter Minimum (For Testing) Recommended (Production)
CPU 1 Core (Shared) 1-2 Cores (Dedicated)
RAM 512 MB 2 GB
Disk 10 GB SSD 20 GB NVMe
Node.js Version 18.x (LTS) 22.x (LTS)

Node Version Manager (NVM) is a must-have tool on any server. We recommend installing Node.js specifically via NVM rather than using apt install nodejs. This lets you switch between versions instantly if a new library suddenly breaks backward compatibility. Installation takes less than 60 seconds: curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash.

Process Management with PM2

The PM2 process manager is the industry standard for managing Node.js applications. It handles automatic restarts on crashes, log rotation, and real-time resource monitoring. In one of our projects, a memory leak in a third-party library caused a bot to eat up 1 GB of RAM in 4 hours. Configuring max_memory_restart in PM2 saved the server from freezing completely.

The ecosystem.config.js configuration file allows you to store all your deployment settings in Git. Here is an example of a working configuration for a bot:

module.exports = {
  apps : [{
    name: "telegram-bot",
    script: "./dist/index.js",
    instances: 1,
    autorestart: true,
    watch: false,
    max_memory_restart: '300M',
    env: {
      NODE_ENV: "production",
      BOT_TOKEN: "your_token_here"
    }
  }]
}

Resource monitoring via the pm2 monit command gives you a visual overview of your server load. If your Node.js bot on a VPS starts consuming more than 15% CPU while idle, it is a sure sign of an infinite loop in an event handler or a database connection issue. For comparison, a similar aiogram deployment on a VPS (Python) uses slightly less RAM when idle, but Node.js wins out when it comes to the speed of asynchronous I/O operations.

Optimizing Memory and the Garbage Collector

By default, the V8 Engine that powers Node.js can reserve up to 1.5 GB of RAM, even if your bot only needs 100 MB. On budget VPS plans with 1 GB of RAM, this triggers Swap usage or causes the operating system's OOM Killer to terminate the process. We use the --max-old-space-size flag to put a hard cap on the runtime's memory appetite.

Through testing, we found that setting --max-old-space-size=512 is the sweet spot for a moderately complex bot. This leaves enough headroom for the OS and file caching. If your bot processes images or generates PDFs, you should bump this limit up to 1024 MB. For high-load systems like trading terminals, latency becomes critical—something we cover in detail in our guide on choosing a VPS for scalping.

Important: Never use sudo to run Node.js processes. Doing so creates a massive security vulnerability. Run your app under an unprivileged user and forward ports (for example, from 80 to 3000) using Nginx or iptables.

Webhooks vs. Long Polling

Long Polling is convenient for development because you don't need a domain name or an SSL certificate. In production, however, it means sending constant HTTP requests to Telegram's servers every 1-2 seconds. Webhooks turn your bot into a passive web server that only wakes up when it receives an incoming POST request.

  • Long Polling: 86,400 requests per day (minimum), creating constant overhead on the network stack.
  • Webhooks: 0 requests while idle, with instant message handling (latency < 50ms).

Setting up Webhooks for a Node.js bot on a VPS requires a Reverse Proxy. Nginx handles this job seamlessly by terminating the SSL connection and forwarding plain HTTP traffic to your local Node.js process. We recommend using free Let's Encrypt certificates, which renew automatically via certbot.

Lessons from the Field: Mistakes and Surprises

What our experience showed: The biggest surprise was log bloat. Over three months, one of our bots generated 14 GB of log files, completely filling up the VPS disk space. The bot stopped responding because its SQLite database couldn't write a single byte. Since then, installing pm2-logrotate has been a mandatory step on our checklist. Setting up the module takes 10 seconds: pm2 install pm2-logrotate.

What surprised us: Contrary to popular belief, Docker isn't always the best choice for running a single bot on a low-spec server. Our benchmarks showed that containerization adds roughly 120-150 MB of RAM overhead (accounting for the Docker Daemon and image layers). On a server with 512 MB of RAM, that is a critical loss. We switched to bare-metal execution via PM2 for smaller projects, which allowed us to run up to 5 different bots on a single micro-server without them impacting each other's performance.

A counterintuitive takeaway: Using TypeScript in production on a VPS can sometimes backfire if transpilation happens directly on the server. We have seen tsc consume up to 1.2 GB of RAM during builds, crashing neighboring services. Now, we always build the project locally or in CI/CD (GitHub Actions) and deploy only the compiled dist folder and node_modules (or run npm install --production) on the server.

Practical Deployment Steps (Checklist)

Below is the step-by-step deployment workflow we use for new projects. Estimated time: 15 minutes. Difficulty: Intermediate.

  1. Prepare the server (2 min): Update packages with sudo apt update && sudo apt upgrade -y and install essential tools (git, curl, htop).
  2. Install Node.js via NVM (2 min): Choose the current LTS version (currently 22.x).
  3. Configure a dedicated user (2 min): Create a separate user with adduser botuser to run the process.
  4. Clone and build (3 min): Run git clone and npm install. If you are using Valebyte, verify that your required ports are open in the control panel.
  5. Configure PM2 (2 min): Create your ecosystem.config.js file and run pm2 start ecosystem.config.js.
  6. Enable auto-start on boot (1 min): Run pm2 startup and pm2 save so your bot comes back online automatically after a VPS reboot.
  7. Monitor the app (1 min): Check your logs with pm2 logs and verify the process state with pm2 status.

To check port availability and network connectivity, you can use an online port scanner to confirm that your Webhook port (such as 8443) is open to incoming connections from Telegram's servers.

FAQ: Frequently Asked Questions

How much RAM do I need for a Node.js bot?
For a simple bot serving 100-500 users, 512 MB is enough. For more complex systems handling media files and a database, plan on 1 GB to 2 GB. According to our data, an average process uses around 85 MB of RAM with 50 concurrent active chats.

Which is better: Docker or PM2?
If you are running a single bot, PM2 is simpler and much lighter on resources. If you are scaling your infrastructure and using CI/CD across a dozen microservices, go with Docker. Docker consumes roughly 15% more resources at smaller scales.

How can I keep my bot from crashing?
Use PM2 for automatic restarts, and set up a `cron` job for a weekly server reboot if you rely on third-party libraries prone to memory leaks. You should also configure a Swap file (at least 1-2 GB) to cushion against traffic spikes.

Do I need Nginx to run a bot?
If you are using Long Polling, no. If you are using Webhooks, it is strongly recommended. Nginx adds a layer of security, simplifies SSL certificate management, and lets you load-balance traffic if you ever decide to spin up a second instance of your bot.

SJ

slipjar.app

Editorial team

The slipjar.app team writes about hosting, servers and infrastructure in plain language.

Was this article helpful?
Servers & Hardware

Read next.

Whole category

New guides every week.

A digest of the best pieces on servers, VPN and self-hosted software. No ads, no spam.

1 email a weekOne-click unsubscribeRU · EN
Only slipjar.app articles, nothing else.