Skip to content

Commit 0197d21

Browse files
author
abhishek
committed
This is the Final Commit for the Fraud Detection backend
0 parents  commit 0197d21

File tree

6,317 files changed

+897929
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

6,317 files changed

+897929
-0
lines changed

.github/workflows/node.js.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3+
4+
name: Node.js CI
5+
6+
on:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
17+
strategy:
18+
matrix:
19+
node-version: [14.x, 16.x, 18.x]
20+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
21+
22+
steps:
23+
- uses: actions/checkout@v3
24+
- name: Use Node.js ${{ matrix.node-version }}
25+
uses: actions/setup-node@v3
26+
with:
27+
node-version: ${{ matrix.node-version }}
28+
cache: 'npm'
29+
- run: npm ci
30+
- run: npm run build --if-present
31+
- run: npm test

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Ignore node_modules directory
2+
node_modules/
3+
4+
# Ignore logs and other generated files
5+
logs/
6+
*.log
7+
*.txt
8+
npm-debug.log*
9+
10+
# Ignore environment-specific files
11+
.env
12+
13+
# Ignore user-specific files
14+
*.suo
15+
*.user
16+
*.userosscache
17+
*.sln.docstates
18+
19+
# Ignore VS Code settings
20+
.vscode/
21+
22+
oldDBConnection.js

Dockerfile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Use an official Node.js image as a base image
2+
FROM node:20
3+
4+
# Set the working directory in the container
5+
WORKDIR /usr/src/app
6+
7+
# Copy package.json and package-lock.json to the working directory
8+
COPY package*.json ./
9+
10+
# Install Node.js dependencies
11+
RUN npm install
12+
13+
# Install additional tools
14+
RUN apt-get update && apt-get install -y \
15+
curl \
16+
whois \
17+
wget \
18+
&& wget https://gitlab.com/api/v4/projects/33695681/packages/generic/nrich/latest/nrich_latest_amd64.deb \
19+
&& dpkg -i nrich_latest_amd64.deb \
20+
&& rm nrich_latest_amd64.deb
21+
22+
# Copy the rest of the application code
23+
COPY . .
24+
25+
# Expose the port your app runs on
26+
EXPOSE 8080
27+
28+
29+
# Install PM2 globally
30+
RUN npm install -g pm2
31+
32+
# Start the Node.js application with PM2
33+
CMD ["pm2-runtime", "start", "pm2.config.js"]
34+
35+
36+

MongoDB/Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Use an official MongoDB image
2+
FROM mongo:latest
3+
4+
# Expose the default MongoDB port
5+
EXPOSE 27017
6+
7+
8+
# Use ARG to declare build-time variables
9+
ARG DB_USER
10+
ARG DB_PASSWORD
11+
ARG DB_DATABASE
12+
13+
# Set environment variables (optional)
14+
ENV MONGO_INITDB_ROOT_USERNAME=$DB_USER
15+
ENV MONGO_INITDB_ROOT_PASSWORD=$DB_PASSWORD
16+
ENV MONGO_INITDB_DATABASE=$DB_DATABASE
17+
18+
19+
# Copy the initialization script to the container
20+
COPY init-script.js /docker-entrypoint-initdb.d/
21+
22+
23+
# Expose custom port for MongoDB (optional)
24+
ENV MONGO_PORT=27017
25+
26+
# Uncomment the line below if you want to enable MongoDB authentication
27+
# ENV MONGO_AUTH=true
28+
29+
#--build-arg DB_HOST=

MongoDB/docker-compose.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: '3.8'
2+
3+
services:
4+
mongodb:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
container_name: fraud-detection-mongodb
9+
ports:
10+
- "27017:27017"
11+
volumes:
12+
- ./MongoDB/fraud-detectionDB:/MongoDB/fraud-detectionDB
13+
environment:
14+
MONGO_INITDB_ROOT_USERNAME: $DB_USER
15+
MONGO_INITDB_ROOT_PASSWORD: $DB_PASSWORD
16+
MONGO_INITDB_DATABASE: $DB_DATABASE

MongoDB/init-script.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// init-script.js
2+
3+
// Connect to the MongoDB server
4+
conn = new Mongo();
5+
6+
// Switch to the 'user_input_data' database
7+
db = db.getSiblingDB('user_input_data');
8+
9+
// Create collections
10+
db.createCollection('messages');
11+
db.createCollection('realBankData');
12+
13+
print("Executing script for userInputOnlyBankNames");
14+
15+
db.createCollection('userInputOnlyBankNames');
16+
db.createCollection('userInputOnlyBankURLs');
17+
18+
// Load CSV data into collections
19+
loadCSV('/docker-entrypoint-initdb.d/messages.csv', 'messages');
20+
loadCSV('/docker-entrypoint-initdb.d/realBankData.csv', 'realBankData');
21+
22+
function loadCSV(filePath, collectionName) {
23+
const fileContent = cat(filePath);
24+
const lines = fileContent.split('\n');
25+
const headers = lines[0].split(',');
26+
27+
const data = [];
28+
for (let i = 1; i < lines.length; i++) {
29+
const values = lines[i].split(',');
30+
const entry = {};
31+
for (let j = 0; j < headers.length; j++) {
32+
entry[headers[j]] = values[j];
33+
}
34+
data.push(entry);
35+
}
36+
37+
// Insert data into the specified collection
38+
db[collectionName].insertMany(data);
39+
}

MongoDB/messages.csv

Lines changed: 498 additions & 0 deletions
Large diffs are not rendered by default.

MongoDB/realBankData.csv

Lines changed: 452 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# fraud_detection_node

app.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const express = require('express');
2+
const bodyParser = require('body-parser');
3+
const path = require('path');
4+
const mainRoutes = require('./src/routes/mainRoutes');
5+
require('dotenv').config();
6+
7+
const app = express();
8+
const port = process.env.PORT || 8080;
9+
10+
app.set('view engine', 'ejs');
11+
app.set('views', path.join(__dirname, 'views'));
12+
app.use(express.static(path.join(__dirname, 'public')));
13+
app.use(bodyParser.urlencoded({ extended: true }));
14+
app.use(express.json());
15+
16+
// Use the mainRoutes for specific routes
17+
app.use('/', mainRoutes);
18+
19+
// Error handling middleware
20+
app.use((err, req, res, next) => {
21+
res.status(err.status || 500).json({ error: err.message });
22+
});
23+
24+
app.listen(port, () => {
25+
console.log(`Server is running on port ${port}`);
26+
});

0 commit comments

Comments
 (0)