connection ECONNREFUSED when trying to push to neon db

Hi people, I'm trying to connect my next.js app with drizzle to neon db, but I'm getting this error when i run push:pg
Error: connect ECONNREFUSED 127.0.0.1:5432
at __node_internal_captureLargerStackTrace (node:internal/errors:464:5)
at __node_internal_exceptionWithHostPort (node:internal/errors:642:12)
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16) {
errno: -61,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 5432
}
Error: connect ECONNREFUSED 127.0.0.1:5432
at __node_internal_captureLargerStackTrace (node:internal/errors:464:5)
at __node_internal_exceptionWithHostPort (node:internal/errors:642:12)
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16) {
errno: -61,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 5432
}
my config looks like this:
//drizzle.config.ts
import type { Config } from "drizzle-kit";

export default {
schema: "./src/server/db/schema.ts",
out: "./drizzle",
driver: "pg",
dbCredentials: {
connectionString: process.env.DATABASE_URL || "",
},
} satisfies Config;
//drizzle.config.ts
import type { Config } from "drizzle-kit";

export default {
schema: "./src/server/db/schema.ts",
out: "./drizzle",
driver: "pg",
dbCredentials: {
connectionString: process.env.DATABASE_URL || "",
},
} satisfies Config;
my db.ts file looks like this:
import { drizzle, PostgresJsDatabase } from "drizzle-orm/postgres-js";
import { migrate } from "drizzle-orm/postgres-js/migrator";
import postgres from "postgres";

// for migrations
const migrationClient = postgres(process.env.DATABASE_URL || "", { max: 1 });
migrate(drizzle(migrationClient), {
migrationsFolder: "./migrations",
});

// for query purposes
const queryClient = postgres(process.env.DATABASE_URL || "");
const db: PostgresJsDatabase = drizzle(queryClient);

export { db };
import { drizzle, PostgresJsDatabase } from "drizzle-orm/postgres-js";
import { migrate } from "drizzle-orm/postgres-js/migrator";
import postgres from "postgres";

// for migrations
const migrationClient = postgres(process.env.DATABASE_URL || "", { max: 1 });
migrate(drizzle(migrationClient), {
migrationsFolder: "./migrations",
});

// for query purposes
const queryClient = postgres(process.env.DATABASE_URL || "");
const db: PostgresJsDatabase = drizzle(queryClient);

export { db };
2 Replies
Angelelz
Angelelz15mo ago
There is a problem with your connection to the DB. It's not related to drizzle
Bozic0909
Bozic0909OP15mo ago
I figured later, the issue was with env variables not being loaded properly even though they exist i managed to fix this issue by using dotenv library
Want results from more Discord servers?
Add your server