Host a discord.js bot (Node.js) for free
Does your bot use discord.js? On Kravn Hosting it runs 24/7 on Node.js 24 or 22, for free, with no credit card. Here is what to prepare, how to upload it and how to fix the most common errors.
Prepare your bot
package.json: your dependencies, and the start file inmain.index.js: your bot's code..env: your Discord token. It stays on the server, never put it on GitHub.
A simple package.json:
{
"name": "my-bot",
"main": "index.js",
"dependencies": {
"discord.js": "^14.16.0",
"dotenv": "^16.4.0"
}
}
The .env file:
DISCORD_TOKEN=your-token
A minimal index.js that answers !ping:
require('dotenv').config();
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent],
});
client.once('ready', () => console.log(`Logged in as ${client.user.tag}`));
client.on('messageCreate', (message) => {
if (message.content === '!ping') message.reply('Pong!');
});
client.login(process.env.DISCORD_TOKEN);
Get it online
- Create your account with Discord, then log in to the panel and open your bot.
- Pick Node.js (24 or 22) in the Startup tab. Leave the main file empty: Kravn runs the file set in
main, orindex.js. - Upload your files in the Files tab or over SFTP. Do not upload
node_modules: it is installed on the server. - Press Start. Kravn runs
npm installon the first start, then only whenpackage.jsonorpackage-lock.jsonchanges.
Is your code on GitHub? Deploy it from GitHub, it updates on every restart.
TypeScript bots
Build your bot before uploading it (for example with tsc), then put the built file in main, for example "main": "dist/index.js". devDependencies are not installed on the server.
Common errors
Cannot find module: the package is missing fromdependencies. If it is indevDependencies, move it and restart.Used disallowed intents: in the Discord developer portal, Bot tab, enable Message Content Intent (and Server Members Intent if you use it).An invalid token was provided: the token is wrong or was reset. Copy the new one into your.env.Cannot use import statement outside a module: your code usesimport. Add"type": "module"to yourpackage.json.- The bot stops with no message: it may be out of memory. Each bot has 256 MB of RAM, enough for a normal bot.
Good to know
- You get 256 MB of RAM, 768 MB of disk and 20% of a CPU core.
- Only a Discord bot is allowed: a website, a proxy or any other program is stopped.
- Your bot is paused if it stays offline for more than 5 days. Your files are kept and you start it again yourself from the panel.
- You can switch from Node.js to Python later, in the Startup tab.
Going further
- Free Discord bot hosting
- Host a Python Discord bot
- Deploy a Discord bot from GitHub
- Frequently asked questions
- A question? Come to the Discord.