add node express & postgresql starter template

This commit is contained in:
2024-05-21 05:53:18 +02:00
parent 80bd52ebe8
commit 87212c27c3
8 changed files with 1570 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
import postgres from "postgres";
const username = process.env.POSTGRES_USER;
const password = process.env.POSTGRES_PASSWORD;
const database = process.env.POSTGRES_DB;
const host = process.env.POSTGRES_HOST;
const port = process.env.POSTGRES_PORT;
if (!username) {
throw new Error("POSTGRES_USER is not set");
}
if (!password) {
throw new Error("POSTGRES_PASSWORD is not set");
}
if (!database) {
throw new Error("POSTGRES_DB is not set");
}
if (!host) {
throw new Error("POSTGRES_HOST is not set");
}
if (!port) {
throw new Error("POSTGRES_PORT is not set");
}
if (isNaN(parseInt(port))) {
throw new Error("POSTGRES_PORT is not a number");
}
export const sql = postgres({
username,
password,
database,
host,
port: parseInt(port),
});