Skip to content

Commit

Permalink
Updated to use env var.
Browse files Browse the repository at this point in the history
  • Loading branch information
erik-sth committed Dec 10, 2023
1 parent 337c4c5 commit fb454e6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 26 deletions.
53 changes: 28 additions & 25 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
name: Build and Test

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
push:
branches: ['main']
pull_request:
branches: ['main']

jobs:
test:
runs-on: ubuntu-latest
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18]
strategy:
matrix:
node-version: [18]

steps:
- name: Checkout code
uses: actions/checkout@v3
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- name: Set up Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Install dependencies
run: npm ci
- name: Install dependencies
run: npm ci

- name: Build
run: npm run build
- name: Set up environment variables
run: echo "MONGODB_URI=${{ secrets.MONGODB_URI }}" >> $GITHUB_ENV

- name: List build artifacts
run: ls dist
- name: Build
run: npm run build

- name: Run tests
run: npm test
- name: List build artifacts
run: ls dist

- name: Run tests
run: npm test
12 changes: 11 additions & 1 deletion src/startup/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@ import mongoose from 'mongoose';

const connectToDatabase = async () => {
try {
await mongoose.connect(process.env.db);
const mongoURI = process.env.MONGODB_URI;

if (!mongoURI) {
throw new Error(
'MongoDB connection string not found in environment variables.'
);
}

await mongoose.connect(mongoURI);

console.log('Connected to MongoDB');
} catch (error) {
console.error('Error connecting to MongoDB:', error.message);
throw error;
Expand Down

0 comments on commit fb454e6

Please sign in to comment.