made updates to load envs and streamline pg pool to cut down on connections #15

Merged
joseph.nelson4456 merged 3 commits from bug/programatically-load-envs into main 2026-05-30 23:52:34 -07:00
12 changed files with 19 additions and 43 deletions
Showing only changes of commit c16eab58a2 - Show all commits
+2 -2
View File
@@ -18,7 +18,7 @@ ENV JWT_SECRET=${JWT_SECRET}
WORKDIR /app
COPY . .
RUN npm install --force --omit=dev && \
RUN npm install --force && \
echo "DATABASE_URL=${DATABASE_URL}" >> .env && \
echo "DB_HOST=${DB_HOST}" >> .env && \
echo "DB_USERNAME=${DB_USERNAME}" >> .env && \
@@ -27,4 +27,4 @@ RUN npm install --force --omit=dev && \
echo "DB_DATABASE=${DB_DATABASE}" >> .env && \
echo "JWT_SECRET=${JWT_SECRET}" >> .env
CMD ["node", "--env-file=.env", "src/app.js"]
CMD ["npm", "run", "docker:start"]
+1
View File
@@ -6,6 +6,7 @@
"scripts": {
"dev": "nodemon src/app.js",
"start": "node src/app.js",
"docker:start": "node --env-file=.env src/app.js",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"migrate": "node-pg-migrate -m ./src/migrations",
+3
View File
@@ -1,3 +1,6 @@
import { loadEnvFile } from 'node:process'
loadEnvFile() // load envs asap
import express from 'express'
import path from 'path'
import cors from 'cors'
+5 -1
View File
@@ -1,5 +1,7 @@
// config/index.js
export const database = {
import { Pool } from 'pg'
const database = {
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
@@ -7,6 +9,8 @@ export const database = {
port: parseInt(process.env.DB_PORT, 10),
}
export const pool = new Pool(database)
export const jwtEnv = {
secret: process.env.JWT_SECRET,
}
+1 -5
View File
@@ -1,14 +1,10 @@
import express from 'express'
import jwt from 'jsonwebtoken'
import bcrypt from 'bcryptjs'
import { database, jwtEnv } from '../../config/index.js'
import { Pool } from 'pg'
import { pool, jwtEnv } from '../../config/index.js'
const router = express.Router()
// Database connection pool
const pool = new Pool(database)
// Route to handle login and issue JWT token
router.post('/login', async (req, res) => {
const { username, password } = req.body
+1 -5
View File
@@ -1,13 +1,9 @@
import express from 'express'
import { Pool } from 'pg'
import { database } from '../../config/index.js'
import { pool } from '../../config/index.js'
import { check, validationResult } from 'express-validator'
const router = express.Router()
// Create a connection pool to the database
const pool = new Pool(database)
// Get all collections
router.get('/', async (req, res) => {
try {
+1 -5
View File
@@ -1,13 +1,9 @@
import express from 'express'
import { Pool } from 'pg'
import { database } from '../../config/index.js'
import { pool } from '../../config/index.js'
import { check, validationResult } from 'express-validator'
const router = express.Router()
// Create a connection pool to the database
const pool = new Pool(database)
// CREATE AN IMAGE
router.post(
'/',
+1 -5
View File
@@ -1,13 +1,9 @@
import express from 'express'
import { Pool } from 'pg'
import { database } from '../../config/index.js'
import { pool } from '../../config/index.js'
import { check, validationResult } from 'express-validator'
const router = express.Router()
// Create a connection pool to the database
const pool = new Pool(database)
// Get all items
router.get('/', async (req, res) => {
const client = await pool.connect()
+1 -5
View File
@@ -1,13 +1,9 @@
import express from 'express'
import { Pool } from 'pg'
import { database } from '../../config/index.js'
import { pool } from '../../config/index.js'
import { check, validationResult } from 'express-validator'
const router = express.Router()
// Create a connection pool to the database
const pool = new Pool(database)
// Create a new location
router.post(
'/',
+1 -5
View File
@@ -1,12 +1,8 @@
import express from 'express'
import { database } from '../../config/index.js'
import { Pool } from 'pg'
import { pool } from '../../config/index.js'
const router = express.Router()
// Create a connection pool to the database
const pool = new Pool(database)
// Create a new role
router.post('/', async (req, res) => {
const { name } = req.body
+1 -5
View File
@@ -1,13 +1,9 @@
import express from 'express'
import { Pool } from 'pg'
import { database } from '../../config/index.js'
import { pool } from '../../config/index.js'
import { check, validationResult } from 'express-validator'
const router = express.Router()
// Create a connection pool to the database
const pool = new Pool(database)
// Get all sets
router.get('/', async (req, res) => {
try {
+1 -5
View File
@@ -1,12 +1,8 @@
import express from 'express'
import { database } from '../../config/index.js'
import { Pool } from 'pg'
import { pool } from '../../config/index.js'
const router = express.Router()
// Create a connection pool to the database
const pool = new Pool(database)
/**
* Get all users.
*/