examples: Error: connect ECONNREFUSED ::1:443 with PostgreSQL and Next.js locally?
I have this defined in .env locally:
DATABASE_URL=postgresql://localhost:5432/mydb
POSTGRES_URL=postgresql://localhost:5432/mydb
I then have this kysely config (where DB is from codgen-kysely):
import 'dotenv/config'
import { createKysely } from '@vercel/postgres-kysely'
import { DB } from 'kysely-codegen'
export const db = createKysely<DB>()
export { sql } from 'kysely'
I then have a seed file at seeds/start.ts:
yarn ts-node -P tsconfig.cli.json seeds/start
/* eslint-disable @typescript-eslint/no-unsafe-argument */
import { db } from '../configurations/kysely'
seed()
async function seed() {
db.insertInto('foo').values(...)
}
What I am getting though is:
$ yarn ts-node -P tsconfig.cli.json seeds/start
$ ./node_modules/.bin/ts-node -P tsconfig.cli.json seeds/start
The database host is 'localhost', which is the default host when none is set. If that's intentional, please ignore this warning. If not, perhaps an environment variable has not been set, or has not been passed to the library?
Error: connect ECONNREFUSED ::1:443
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1487:16) {
errno: -61,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '::1',
port: 443
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Why is it trying to connect to port 443 when I specified 5432 in the .env? Do I need to open up port 443 locally? That seems weird. How do I get around this locally?
I was able to run the kysely migrations fine, but not the seeds now, using the @vercel/postgres-kysely package.
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 13
- Comments: 19
While I was following the Next.js dashboard-app tutorial, I had a similar problem connecting DB locally, so I came here while searching. After doing this and that, I found a solution and want to share it for the other people like me. I connected to DB using pg library instead
@vercel/postgreslibrary and made sql template literal work using code snippet of sql-pg library.Here is a modified seed.js file snippet.
Don’t forget to require
Clientfrompg.Just to give my complete snippets that is worked like a charm, thanks @NeuroWhAI and @Tobbe for the reference! 🚀
Since I want to use my
.env, then I need to install dotenv as well:And this is my complete
seed.js:My local
.env(just do it for example for other folks):From my experience, chapter 6 was the most time consuming, like 10:2 comparing to other chapters of the course. I think it would benefit from adding a small hint there about how to do local pg connection. I have no doubts that a real portion of users do go with local db setup in the course.
I tried to do what is said in the tutorial. The database is working correctly, however, when I try to use it in my nuxt 3 application I get the error
[uncaughtException] TypeError: g.getRandomValues is not a functionI’m using node 18.14.2
I got this working for Drizzle using a docker-compose setup and a tiny bit of extra config code described here: https://gal.hagever.com/posts/running-vercel-postgres-locally.
My
db.tsfile:So both postgres and the web socket proxy are running in a local container. It should also be possible to just have the web socket proxy in a docker container (or even both on your host machine) but I didn’t try that.
So many thanks @Schniz for that article!
I’m also facing this issue. Please provide an example of how to switch to a locally installed database when using this package.
@NeuroWhAI Thank you so much for sharing that snippet! Only thing I changed was the connection parameters for creating the client to look like this: