How do I create my first Node.js bot?
Set up a Node.js environment, import the project, and define the start command. Bot hosting provides Node.js, a file manager and a console.
Bot hosting provides Node.js, a file manager and a console. The Discord token should be stored in an environment variable.
Step-by-step procedure
-
Prepare the project
Your repository should contain package.json, an entry file and a startup script.
-
Order a bot
Choose Bots, then select Node.js as the environment in the order form.
-
Import the files
Use the GitHub import or upload an archive without node_modules.
-
Add the token
Create a DISCORD_TOKEN variable in Startup or a .env file excluded from the repository.
-
Install and start
Click “Start” in the console: the platform installs the dependencies from package.json, then runs the start script.
Minimal package.json
{
"scripts": { "start": "node src/index.js" },
"dependencies": { "discord.js": "^14.0.0" }
}
Minimal src/index.js file
const { Client, Events, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.once(Events.ClientReady, (c) => {
console.log(`Logged in as ${c.user.tag}`);
});
client.login(process.env.DISCORD_TOKEN);
Before you start
Test the bot on your computer with the same major Node.js version as the hosting: 20, 22 or 24. You can change the version later in the “Startup” tab, “Docker image” card.
- A package.json at the root, with discord.js in the dependencies and a start script.
- The lockfile (package-lock.json, yarn.lock or pnpm-lock.yaml) so the exact tested versions are installed.
- A .gitignore that excludes node_modules and .env.
What the platform does
At every start, the platform compares package.json and the lockfile with the last installation. If they changed, it reinstalls the dependencies before launching the bot, and the console shows a line such as “Dependencies installed in 8 s.”. You do not need to open a terminal.
Without a defined command, the platform looks for the entry point: the start script, then the main field of package.json, then a file such as index.js, bot.js or src/index.js. A start script like node src/index.js is run directly, with no npm process in front of the bot.
A .ts start file is run with tsx, from Node.js 22 onwards. If your start script points to a compiled file that does not exist yet, the platform first runs the build script of package.json.
Check that everything works
Open the console after the start. You should see the launched command, for example $ node src/index.js, then the login message of your code. In Discord, the bot appears online in the member list a few seconds later.
Frequently asked questions
What does Error [TokenInvalid]: An invalid token was provided. mean?
discord.js received no usable token: the DISCORD_TOKEN variable is empty, misnamed or holds the application ID. Paste the token from the “Bot” tab of the Discord portal into “Startup”, then restart. A bot token has three parts separated by dots.
Why does the console show Error: Cannot find module 'discord.js'?
The package is missing from the dependencies or the last installation failed. Add it with npm install discord.js on your computer, upload the new package.json and its lockfile, then restart. When the console recognises a missing module, it also offers an “Install discord.js” button that adds it to package.json and restarts the bot.
What should I do about SyntaxError: Cannot use import statement outside a module?
Your code uses the import syntax, but Node.js reads it as CommonJS. Add "type": "module" to package.json or rename the file to .mjs, then restart the bot.
The bot stops with Used disallowed intents, why?
The code requests a privileged intent (MessageContent, GuildMembers or GuildPresences) that is not enabled for the application. Enable it in the Discord developer portal, “Bot” tab, “Privileged Gateway Intents” section, then restart.