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
Percy3mo ago
Project ID: N/A
abudgethuman
abudgethuman3mo ago
N/A
Brody
Brody3mo ago
are you commiting your node_modules to github? are you storing your sqlite file in a railway volume?
abudgethuman
abudgethuman3mo ago
everything is on the github repo the modules and db
Brody
Brody3mo ago
you don't want either to be in github
abudgethuman
abudgethuman3mo ago
ok how can i set it up then
Brody
Brody3mo 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
abudgethuman3mo ago
i need to pay for the database??
Brody
Brody3mo ago
yes of course, you'd pay for it's cpu, memory, and disk
abudgethuman
abudgethuman3mo ago
see im a cheap skate thats why i used github for it
Brody
Brody3mo ago
that's only going to cause headaches unless setup properly
abudgethuman
abudgethuman3mo 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
Brody3mo ago
like I said, I would highly recommend you use postgres
abudgethuman
abudgethuman3mo ago
ok Ngl ima just switch to aws
Brody
Brody3mo ago
may i ask why?
abudgethuman
abudgethuman3mo ago
More simple And I have access to the actual machine
Brody
Brody3mo ago
interesting answer, it's definitely not simpler, and for this use-case you also definitely don't need access to the machine
abudgethuman
abudgethuman3mo ago
I find it easier to build packages and setup the project through a command line
Brody
Brody3mo ago
on railway you simply push to github, there's no setup besides adding environment variables
abudgethuman
abudgethuman3mo ago
how do i install the node modules then
Brody
Brody3mo ago
its done automatically
abudgethuman
abudgethuman3mo ago
its still telling me it has invalid ELF headers
Brody
Brody3mo ago
are you still including your node_modules folder and sqlite file in github?
abudgethuman
abudgethuman3mo ago
no its in the .gitignore
Brody
Brody3mo ago
that doesnt remove things from the repo
abudgethuman
abudgethuman3mo ago
oh should i just delete it then?
Brody
Brody3mo ago
yes
abudgethuman
abudgethuman3mo ago
alr ok i got it working thank you
Brody
Brody3mo ago
if you arent going to use postgres, make sure your code stores the sqlite file in a volume
abudgethuman
abudgethuman3mo ago
why?
Brody
Brody3mo ago
if you dont store the sqlite file in a volume the data in the sqlite file will not persist between deployments
abudgethuman
abudgethuman3mo ago
oh ok and how would it work with postgres?
Brody
Brody3mo ago
you connect to postgres and use that instead of sqlite
abudgethuman
abudgethuman3mo ago
What’s the benefit in that?
Brody
Brody3mo ago
you dont have to figure out how volumes works 🤣
abudgethuman
abudgethuman3mo ago
Oh ok so my sqlite code will still work? and what do i need to do to get it set up
Brody
Brody3mo 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
abudgethuman3mo ago
so i just add a new service in the project?
Brody
Brody3mo ago
yeah add postgres to the project
abudgethuman
abudgethuman3mo ago
ok how do i connect to it in my code now?
Brody
Brody3mo 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
abudgethuman3mo 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
Brody3mo ago
haha thank you
abudgethuman
abudgethuman2mo ago
Ok i have modified my code to work with postgres. Where do i find the connection string?
Brody
Brody2mo 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
abudgethuman2mo ago
ok i found it but im trying to connect to it from my local pc but its not letting me
Brody
Brody2mo ago
what do you mean not letting you
abudgethuman
abudgethuman2mo 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
Brody2mo ago
that says 127.0.0.1
abudgethuman
abudgethuman2mo ago
ya local host
Brody
Brody2mo ago
i can assure you that you are not running railway locally
abudgethuman
abudgethuman2mo ago
yes i know im trying to run my website localy to test the database
Brody
Brody2mo ago
you need to connect to postgres on railway
abudgethuman
abudgethuman2mo ago
what do you mean? i have set up the database on railway do i need to deploy it for it to work
Brody
Brody2mo ago
and you need to connect to it
abudgethuman
abudgethuman2mo ago
const db = new Client({ connectionString: asfasfasf, ssl: { rejectUnauthorized: false, }, }); db.connect() this is how i am
Brody
Brody2mo ago
bruh asfasfasf ???
abudgethuman
abudgethuman2mo ago
ya im not sending the string here i have it tho trust
Brody
Brody2mo ago
let me know when this is done
abudgethuman
abudgethuman2mo ago
idk it worked when i pushed the changes to the site
Brody
Brody2mo ago
I don't think I can continue helping if you aren't willing to follow along with my help
abudgethuman
abudgethuman2mo ago
i am willing i just dont understand railway enough to do some things
Brody
Brody2mo ago
it was just adding a variable
abudgethuman
abudgethuman2mo ago
oh i see like this? DATABASE_URL ${{Postgres.DATABASE_URL}}
Brody
Brody2mo ago
no, I typed it out above, all you need to do is copy and paste
abudgethuman
abudgethuman2mo ago
i did sorry that wasnt the rw raw
Brody
Brody2mo ago
okay and now if you click the eye icon, does it show the full url
abudgethuman
abudgethuman2mo ago
no it just says shows this: ${{Postgres.DATABASE_URL}}
Brody
Brody2mo ago
click the eye icon, not the edit icon
abudgethuman
abudgethuman2mo ago
No description
Brody
Brody2mo ago
you need to deploy the changes
abudgethuman
abudgethuman2mo ago
ok
Brody
Brody2mo ago
and have you used that environment variable in code?
abudgethuman
abudgethuman2mo ago
i put in .env?
Brody
Brody2mo ago
have you used that environment variable in code?
abudgethuman
abudgethuman2mo ago
no i always hardcode everything lol
Brody
Brody2mo ago
let's not do that going forward, please use that environment variable in code
abudgethuman
abudgethuman2mo ago
ok ok sry im very new to deploying websites all bots before this
Brody
Brody2mo ago
seems like you are overthinking things and it's clouding your judgement, it's just simple steps, one at a time
abudgethuman
abudgethuman2mo ago
yes what should the variable look like in my code
Brody
Brody2mo 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
abudgethuman2mo ago
i thought that was for the service only? i put the same thing in my code?
Brody
Brody2mo ago
let's see the code please
abudgethuman
abudgethuman2mo ago
const db = new Client({ connectionString: process.env.DATABASE_URL, }); that right?
Brody
Brody2mo ago
yep looks good to me
abudgethuman
abudgethuman2mo ago
so that will just use the railway variables?
Brody
Brody2mo 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
abudgethuman2mo ago
ok sounds good thank you so much also what would i use the database private url for?
Brody
Brody2mo 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
abudgethuman2mo 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
Brody2mo ago
you would still connect to the database that runs on railway
abudgethuman
abudgethuman2mo ago
what about the node_modules?
Brody
Brody2mo ago
what about it??
abudgethuman
abudgethuman2mo ago
Do I need to reinstall them when I’m testing?? Or is their a way to access them from railway
Brody
Brody2mo ago
they automatically get installed on railway during the build process