Bot Uptime

How to Host a Discord.js v14 Bot 24/7 for Free (Complete Step-by-Step Guide)

Running a Discord.js bot from your personal laptop works during early prototyping, but the moment your PC sleeps, restarts, or loses Wi-Fi, your server loses moderation, welcome messages, and slash commands. Moving to an always-on Linux container fixes that permanently — and with modern Node.js 22 containers, even a 256 MB RAM free tier can easily serve multiple Discord communities.

1. Prepare Your Project Structure

Before uploading your code to any Linux host, make sure your project has a clean entry file (usually index.js) and an accurate package.json file listing every dependency. Never upload your local node_modules folder — containers run npm install automatically on first boot, which builds clean Linux-compatible binaries and saves upload time.

Also double-check that you have created your application in the Discord Developer Portal, enabled the Bot user, and toggled on only the Privileged Gateway Intents your bot actually reads (for example, GuildMembers for join/leave logs or MessageContent only if you parse prefix commands).

package.json
{
  "name": "my-discord-bot",
  "version": "1.0.0",
  "main": "index.js",
  "engines": {
    "node": ">=20.0.0"
  },
  "dependencies": {
    "discord.js": "^14.16.3",
    "dotenv": "^16.4.5"
  }
}

2. Write a Clean, Memory-Efficient Discord.js v14 Entry File

A production Discord.js bot should load its token from process.env.DISCORD_TOKEN rather than hardcoding it in source files, handle unhandled promise rejections gracefully so transient Discord API hiccups never crash the process, and register slash commands cleanly on startup.

If you are running on a 256 MB RAM container, avoid caching thousands of old messages forever. Using Discord.js v14 sweepers or default lightweight caches keeps steady memory usage around 45–80 MB.

index.js
require('dotenv').config();
const { Client, GatewayIntentBits, Events } = require('discord.js');

const client = new Client({
  intents: [GatewayIntentBits.Guilds]
});

client.once(Events.ClientReady, (c) => {
  console.log(`[Ready] Logged in as ${c.user.tag} across ${c.guilds.cache.size} server(s).`);
});

client.on(Events.InteractionCreate, async (interaction) => {
  if (!interaction.isChatInputCommand()) return;
  if (interaction.commandName === 'ping') {
    await interaction.reply(`Pong! Gateway latency: ${client.ws.ping}ms`);
  }
});

process.on('unhandledRejection', (err) => {
  console.error('[UnhandledRejection]', err);
});

client.login(process.env.DISCORD_TOKEN);

3. Upload Files, Configure .env, and Start Your Container

Inside your Bot Uptime dashboard, create a new Node.js bot container. Open the Files tab (or launch the full-screen Browser IDE) and upload package.json, index.js, and any command folders — or import directly from a public GitHub repository.

Next, create a file named .env in the root folder containing DISCORD_TOKEN=your_real_token_here. Never commit .env to GitHub. Finally, verify that Startup Settings has JS_FILE set to index.js and press Start. Watch the Live Console as npm installs discord.js and prints your Ready line.

  • Delete or exclude node_modules/ before zipping or uploading your project.
  • Keep your token strictly inside .env (chmod private inside your isolated container).
  • Use the Startup Settings tab if your entry file lives inside src/bot.js instead of index.js.
  • Monitor RAM and CPU gauges in real time to verify your bot stays well under container limits.

4. Keeping Node.js Smooth Under 256 MB RAM

Node.js V8 garbage collection automatically expands heap usage if left unconstrained on small containers. Keeping dependencies lean (skip heavy headless browsers like Puppeteer unless you are on a 2 GB Developer or 6 GB Pro container) and avoiding storing large image buffers in global arrays ensures rock-solid 24/7 uptime without out-of-memory restarts.

If your bot grows to dozens of servers, canvas image generation, or SQLite analytics, upgrading to Developer (2 GB RAM · 100% CPU) or Pro (6 GB RAM · 200% CPU) seamlessly scales your container resources without losing a single file.

Frequently Asked Questions

Should I upload my node_modules folder?

No. Always exclude node_modules and upload only package.json (and package-lock.json). The Linux container installs clean packages automatically on startup.

Why did my bot say "Cannot find module index.js"?

Open Bot Settings / Startup and set JS_FILE to match your exact main file path (for example src/index.js or bot.js), making sure capitalization matches Linux case sensitivity.

Does Node.js 22 support native fetch and SQLite?

Yes! Node.js 22 includes native fetch() and built-in node:sqlite, meaning you often do not need heavy native C++ packages like node-fetch or compiled addons.

Ready to deploy your bot 24/7?

Launch a custom Discord, Telegram, or WhatsApp container (Python, Node.js, Java, Rust) with Managed Databases and Free AI Agents — or deploy a ready-made Discord bot in 1 click on Bot Uptime.