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