R
Join ServerRailway
✋|help
Deployment without a manually uploaded node module folder didn't work
As the title suggests, I had a really simple script that I needed to deploy and without my node modules folder manually uploaded (note, there was a package.json and all that), I couldn't properly deploy the script and was getting undefined errors from my dependancies.
e629e6f4-8257-472b-8ef9-34809b5acd29
finally

🤐
working on something right now, ill be back soon
in the meantime, screenshots please
Ready!
Balance is satisfactory, currently 0.469175743382926796 ETH.
/app/index.js:50
channel.send({
^
TypeError: Cannot read properties of undefined (reading 'send')
at /app/index.js:50:13
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Node.js v18.12.1
/// Dependancies ///
const { ethers } = require('ethers');
const { Client, GatewayIntentBits, EmbedBuilder } = require('discord.js');
/// Discord Token ///
const discordToken =
'XXX';
/// Create a new client instance ///
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
/// When the client is ready, run this code (only once) ///
client.once('ready', () => {
console.log('Ready!');
});
/// Ethers Alchemy Provider ///
const provider = new ethers.AlchemyProvider(
'homestead',
'XXX'
);
const getBalance = async () => {
provider
.getBalance('
xxx')
.then((balance) => {
let ethBalance = ethers.formatEther(balance);
const channel = client.channels.cache.get('XXX');
if (ethBalance < 0.1) {
let warningEmbed = new EmbedBuilder()
.setColor(0xff0000)
.setTitle('Balance Warning! Top up ASAP!')
.setDescription(`Current Balance: ${ethBalance} ETH`);
console.log(
`WARNING: Balance is under 0.15 (${ethBalance} ETH), top up ASAP! Sending alert...`
);
channel.send({
content: 'XXX',
embeds: [warningEmbed],
});
} else {
let standardEmbed = new EmbedBuilder()
.setColor(0x00ff00)
.setTitle('Balance Check')
.setDescription(`Current Balance: ${ethBalance}`);
console.log(`Balance is satisfactory, currently ${ethBalance} ETH.`);
channel.send({
embeds: [standardEmbed],
});
}
});
};
/// Initialize Watcher ///
const startWatcher = async () => {
await client.login(discordToken);
getBalance();
let getBalanceInterval = setInterval(getBalance, 21600000);
};
startWatcher();
There we go, ofc just lmk if I'm missing anything
take your time, no rush at all, apologies for the wait haha
obligatory question, have you modified anything in your local node_modules folder?
also, callback hell
async but no await
no sir, never
can i see a screenshot of the variables tab in the service
just node v18
okay i was hoping so
yep, always

little side track though, im seeing a few
'XXX'
meaning you stored secrets as plain text in your code?yeah, this is a one-off discord bot for a super small function
someone could get hold of that secret and it really wouldnt matter haha
still though, please use service variables going forward, its just good practice
service variables?
like that
but for your discord token
shit, railway keeps getting better, ill be sure to peep docs for how that works and get on it immediately, thanks dude!
add a variable in there then access it with process.env.<variable name>
you're the best
okay but thats not your issue
i have many
glad we could fix one
now back on track, locally, delete the node_modules folder then run
npm i
and tell me if your code still worksworked
side note
ill work on callback hell later 

its just
const balance = await provider.getBalance('xxx');
const getBalance = async () => {
const initBalance = await provider.getBalance('XXX')
let ethBalance = ethers.formatEther(initBalance);
is that less hellish
lol
sorry, i swear i didnt open this for JS lessons 

ethBalance can be a const
done
ty sensei
is
client.channels.cache.get
a promise?dont believe so
would be if it was without cache
actually i may be confusing versions of discord.js
forget that
okay so at this point im just googleing for the error, so will you take over that for now
are you referring to:
TypeError: Cannot read properties of undefined (reading 'send')
at /app/index.js:50:13
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Node.js v18.12.1
What.... the sweet hell, I just deleted node modules again and it worked

Are you deploying from git?
wdym? to railway?
from git to railway?
I sync changes to my repo and then railway redeploys
is my flow
So currently you have a .gitignore with
node_modules/
and theres now no node_modules folder on git?correct
and it works, no more undefined?
nope.
lol
okay well i dont know what was fixed but yay
it was your energy
the vibes
Thank you so much for taking the time, I'm sorry this didn't sort itself out cleanly, but I did seriously learn some really solid lessons from you in the process
haha thank you, glad it worked out
