ECONNRESET error when trying to create a database from a javascript file
So I'm receiving the below error when trying to create a table from a js file using postgres. In the annexed images you can see how I wrote the code for creating the table. I was following a video doing the same, for him it worked, but not for me. The error doesn't happen if I use async, but the table doesn't get created either.
What's happening here and how to solve it?


7 Replies
conscious-sapphire•11mo ago
Hey @Amodeus R. this is odd - that SQL you are using is MySQL syntax. PostgreSQL has no "ON UPDATE" - see https://www.morling.dev/blog/last-updated-columns-with-postgres/
Last Updated Columns With Postgres
In many applications it’s a requirement to keep track of when a record was created and updated the last time.
Often, this is implemented by having columns such as created_at and updated_at within each table.
To make things as simple as possible for application developers,
the database itself should take care of maintaining these values automati...
conscious-sapphire•11mo ago
if I remove the
ON UPDATE CURRENT_TIMESTAMP I am able to run your exact code fine.
but your error seems to indicate something else on your system is misconfiguredstormy-goldOP•11mo ago
oh I see, so I got trolled by ChatGPT then... I'll try fixing that then, I'll say if I it worked for me, thanks for the answer!
conscious-sapphire•11mo ago
classic ChatGPT gaslighting
stormy-goldOP•11mo ago
Unfortunately just changing the syntax didn't make it work, but what else could be misconfigured? Isn't all what I show the necessary to make it work?
conscious-sapphire•11mo ago
the error is coming from the postgres.js module - there is a whole stack of dependencies below your code that could be causing the error... What version of Node are you using?
node -v ? What version of postgres.js is listed in your package.json file?
oh you know what - one other thing I just noticed. You may need to:
1. npm install dotenv
2. Add the init to your db.js file
stormy-goldOP•11mo ago
Indeed it had to do with the dotenv file. I was trying to use the built-in dotent from nodejs, but it wasn't working. Installing the dotenv dependency fixed it, thanks for the help :D