Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Node.js CI

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

jobs:
build:

runs-on: ubuntu-latest

services:
mongodb:
image: mongo:latest
ports:
- 27017:27017
options: >-
--health-cmd mongosh
--health-interval 10s
--health-timeout 5s
--health-retries 5

strategy:
matrix:
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: backend/package-lock.json

- name: Install Dependencies
working-directory: ./backend
run: npm ci

- name: Run Tests
working-directory: ./backend
env:
MONGO_URL: mongodb://localhost:27017/test_db
PORT: 8000
NODE_ENV: test
run: npm test
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ firebase-debug.log
serviceAccount.json

# Package files
package-lock.json

Comment thread
Shravanthi20 marked this conversation as resolved.
yarn.lock
.tmp
.temp
15 changes: 9 additions & 6 deletions backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,15 @@ app.use(express.json());
app.use(express.urlencoded({ extended: true }));

// MongoDB Connection with better error handling
const mongoUri = process.env.MONGODB_URI || "mongodb://127.0.0.1:27017/smart-rent-system";

if (!mongoUri) {
console.error("Critical Error: MongoDB connection string is missing!");
process.exit(1);
}

mongoose
.connect(process.env.MONGODB_URI)
.connect(mongoUri)
.then(() => {
console.log("MongoDB Connected Successfully");
})
Expand Down Expand Up @@ -192,8 +199,4 @@ app.use((err, req, res, next) => {
});
});

const PORT = process.env.PORT || 8000;

app.listen(PORT, () => {
console.log(`Server running in ${process.env.NODE_ENV} mode on port ${PORT}`);
});
module.exports = app;
Loading