Sqlite 3 Invalid ELF header

Hi my site uses sqlite3 for the database and has been working fine. I just finished a new update and committed the changes to the GitHub repo my railway app is connected to but it crashed with this error: /node_sqlite3.node: invalid ELF header. I looked it up and it apperently its because i built the package on my local machine so it isnt working for the host machine. I don't know how i could build it on the host though so please help.
95 Replies
Percy
Percy8mo ago
Project ID: N/A
abudgethuman
abudgethumanOP8mo ago
N/A
Brody
Brody8mo ago
are you commiting your node_modules to github? are you storing your sqlite file in a railway volume?
abudgethuman
abudgethumanOP8mo ago
everything is on the github repo the modules and db
Brody
Brody8mo ago
you don't want either to be in github
abudgethuman
abudgethumanOP8mo ago
ok how can i set it up then
Brody
Brody8mo ago
remove both from GitHub and then add them to the .gitignore, then change your code to store the sqlite database in a volume https://docs.railway.app/reference/volumes but honestly it would likely be far easier if you used postgres
abudgethuman
abudgethumanOP8mo ago
i need to pay for the database??
Brody
Brody8mo ago
yes of course, you'd pay for it's cpu, memory, and disk
abudgethuman
abudgethumanOP8mo ago
see im a cheap skate thats why i used github for it
Brody
Brody8mo ago
that's only going to cause headaches unless setup properly
abudgethuman
abudgethumanOP8mo ago
ok i need to go for now but would you be able to help me set it up some other time? with the volume and everything
Brody
Brody8mo ago
like I said, I would highly recommend you use postgres
abudgethuman
abudgethumanOP8mo ago
ok Ngl ima just switch to aws
Brody
Brody8mo ago
may i ask why?
abudgethuman
abudgethumanOP8mo ago
More simple And I have access to the actual machine
Brody
Brody8mo ago
interesting answer, it's definitely not simpler, and for this use-case you also definitely don't need access to the machine
abudgethuman
abudgethumanOP8mo ago
I find it easier to build packages and setup the project through a command line
Brody
Brody8mo ago
on railway you simply push to github, there's no setup besides adding environment variables
abudgethuman
abudgethumanOP8mo ago
how do i install the node modules then
Brody
Brody8mo ago
its done automatically
abudgethuman
abudgethumanOP8mo ago
its still telling me it has invalid ELF headers
Brody
Brody8mo ago
are you still including your node_modules folder and sqlite file in github?
abudgethuman
abudgethumanOP8mo ago
no its in the .gitignore
Brody
Brody8mo ago
that doesnt remove things from the repo
abudgethuman
abudgethumanOP8mo ago
oh should i just delete it then?
Brody
Brody8mo ago
yes
abudgethuman
abudgethumanOP8mo ago
alr ok i got it working thank you
Brody
Brody8mo ago
if you arent going to use postgres, make sure your code stores the sqlite file in a volume
abudgethuman
abudgethumanOP8mo ago
why?
Brody
Brody8mo ago
if you dont store the sqlite file in a volume the data in the sqlite file will not persist between deployments
abudgethuman
abudgethumanOP8mo ago
oh ok and how would it work with postgres?
Brody
Brody8mo ago
you connect to postgres and use that instead of sqlite
abudgethuman
abudgethumanOP8mo ago
What’s the benefit in that?
Brody
Brody8mo ago
you dont have to figure out how volumes works 🤣
abudgethuman
abudgethumanOP8mo ago
Oh ok so my sqlite code will still work? and what do i need to do to get it set up
Brody
Brody8mo ago
with postgres? it's not exactly 1:1 compatible don't overthink, you deploy postgres and then have your code connect to it
abudgethuman
abudgethumanOP8mo ago
so i just add a new service in the project?
Brody
Brody8mo ago
yeah add postgres to the project
abudgethuman
abudgethumanOP8mo ago
ok how do i connect to it in my code now?
Brody
Brody8mo ago
that's not quite a railway specific question, and you would definitely be far better off watching a YouTube video for that, a YouTube video could do a much better explanation than me
abudgethuman
abudgethumanOP8mo ago
Ok sounds good You know you’re really getting ripped off here Brody Railway should be paying you for dealing with people like me all day
Brody
Brody8mo ago
haha thank you
abudgethuman
abudgethumanOP8mo ago
Ok i have modified my code to work with postgres. Where do i find the connection string?
Brody
Brody8mo ago
you dont necessarily need to find it, you need to reference it, on your apps service you would set the following service variable -
DATABASE_URL=${{Postgres.DATABASE_URL}}
DATABASE_URL=${{Postgres.DATABASE_URL}}
and then you use the DATABASE_URL environment variable in your code
abudgethuman
abudgethumanOP8mo ago
ok i found it but im trying to connect to it from my local pc but its not letting me
Brody
Brody8mo ago
what do you mean not letting you
abudgethuman
abudgethumanOP8mo ago
Error: connect ECONNREFUSED 127.0.0.1:5432 at createConnectionError (node:net:1634:14) at afterConnectMultiple (node:net:1664:40) { errno: -61, code: 'ECONNREFUSED', syscall: 'connect', address: '127.0.0.1', port: 5432 }
Brody
Brody8mo ago
that says 127.0.0.1
abudgethuman
abudgethumanOP8mo ago
ya local host
Brody
Brody8mo ago
i can assure you that you are not running railway locally
abudgethuman
abudgethumanOP8mo ago
yes i know im trying to run my website localy to test the database
Brody
Brody8mo ago
you need to connect to postgres on railway
abudgethuman
abudgethumanOP8mo ago
what do you mean? i have set up the database on railway do i need to deploy it for it to work
Brody
Brody8mo ago
and you need to connect to it
abudgethuman
abudgethumanOP8mo ago
const db = new Client({ connectionString: asfasfasf, ssl: { rejectUnauthorized: false, }, }); db.connect() this is how i am
Brody
Brody8mo ago
bruh asfasfasf ???
abudgethuman
abudgethumanOP8mo ago
ya im not sending the string here i have it tho trust
Brody
Brody8mo ago
let me know when this is done
abudgethuman
abudgethumanOP8mo ago
idk it worked when i pushed the changes to the site
Brody
Brody8mo ago
I don't think I can continue helping if you aren't willing to follow along with my help
abudgethuman
abudgethumanOP8mo ago
i am willing i just dont understand railway enough to do some things
Brody
Brody8mo ago
it was just adding a variable
abudgethuman
abudgethumanOP8mo ago
oh i see like this? DATABASE_URL ${{Postgres.DATABASE_URL}}
Brody
Brody8mo ago
no, I typed it out above, all you need to do is copy and paste
abudgethuman
abudgethumanOP8mo ago
i did sorry that wasnt the rw raw
Brody
Brody8mo ago
okay and now if you click the eye icon, does it show the full url
abudgethuman
abudgethumanOP8mo ago
no it just says shows this: ${{Postgres.DATABASE_URL}}
Brody
Brody8mo ago
click the eye icon, not the edit icon
abudgethuman
abudgethumanOP8mo ago
No description
Brody
Brody8mo ago
you need to deploy the changes
abudgethuman
abudgethumanOP8mo ago
ok
Brody
Brody8mo ago
and have you used that environment variable in code?
abudgethuman
abudgethumanOP8mo ago
i put in .env?
Brody
Brody8mo ago
have you used that environment variable in code?
abudgethuman
abudgethumanOP8mo ago
no i always hardcode everything lol
Brody
Brody8mo ago
let's not do that going forward, please use that environment variable in code
abudgethuman
abudgethumanOP8mo ago
ok ok sry im very new to deploying websites all bots before this
Brody
Brody8mo ago
seems like you are overthinking things and it's clouding your judgement, it's just simple steps, one at a time
abudgethuman
abudgethumanOP8mo ago
yes what should the variable look like in my code
Brody
Brody8mo ago
I had written it out for you here if you aren't familiar with reading environment variables in code then node has documentation for that
abudgethuman
abudgethumanOP8mo ago
i thought that was for the service only? i put the same thing in my code?
Brody
Brody8mo ago
let's see the code please
abudgethuman
abudgethumanOP8mo ago
const db = new Client({ connectionString: process.env.DATABASE_URL, }); that right?
Brody
Brody8mo ago
yep looks good to me
abudgethuman
abudgethumanOP8mo ago
so that will just use the railway variables?
Brody
Brody8mo ago
yes, at least when on railway, locally you will need to use the railway cli with railway run <whatever command you use to start your app for local development>
abudgethuman
abudgethumanOP8mo ago
ok sounds good thank you so much also what would i use the database private url for?
Brody
Brody8mo ago
connecting to it from within the private network to avoid egress fees, but I don't know how to explain a solution to that in a simple manner
abudgethuman
abudgethumanOP8mo ago
ok Hi im trying to test my site locally but i dont know how to do it with out deploying it for everyone to see
Brody
Brody8mo ago
you would still connect to the database that runs on railway
abudgethuman
abudgethumanOP8mo ago
what about the node_modules?
Brody
Brody8mo ago
what about it??
abudgethuman
abudgethumanOP8mo ago
Do I need to reinstall them when I’m testing?? Or is their a way to access them from railway
Brody
Brody8mo ago
they automatically get installed on railway during the build process
Want results from more Discord servers?
Add your server