diff --git a/.npmrc b/.npmrc
new file mode 100644
index 0000000..8505a79
--- /dev/null
+++ b/.npmrc
@@ -0,0 +1,4 @@
+#//192.168.33.10:8081/repository/dockernodejs/:username=admin
+#//192.168.33.10:8081/repository/dockernodejs/:email=ci@example.com
+#always-auth=true
+#registry=http://192.168.33.10:8081/repository/dockernodejs/
diff --git a/README.md b/README.md
deleted file mode 100644
index a60641b..0000000
--- a/README.md
+++ /dev/null
@@ -1 +0,0 @@
-# Nodejs-Java-Project
\ No newline at end of file
diff --git a/nodejs-jenkinsfile b/nodejs-jenkinsfile
new file mode 100644
index 0000000..7ee2247
--- /dev/null
+++ b/nodejs-jenkinsfile
@@ -0,0 +1,101 @@
+pipeline {
+ agent any
+
+ environment {
+ nexusurl='http://192.168.33.11:8081/repository/NODEJS_JAVA_Project/'
+
+ }
+
+ tools {
+ nodejs 'NodeJS' // Specify the Node.js version to use for the build
+ }
+
+ stages {
+ // Checkout stage to pull the code from the GitHub repository
+ stage('Checkout') {
+ steps {
+ git branch: 'nodejs', url: 'https://github.com/Coding4Deep/Nodejs-Java-Project.git'
+ }
+ }
+
+ // Install dependencies using npm
+ stage('Install Dependencies') {
+ steps {
+ sh 'npm install' // Install project dependencies
+ }
+ }
+
+ // Run unit tests and Jest tests
+ stage('Unit + Jest Test') {
+ steps {
+ sh 'npm run test' // Run unit tests
+ sh 'npx jest' // Run Jest tests
+ sh 'npm pack'
+ }
+ }
+
+ stage('Upload to Nexus') {
+ steps {
+ script {
+ echo "Deploying to Nexus..."
+
+ sh "npm publish --registry=${nexusurl}"
+ }
+ }
+ }
+
+ // SonarQube analysis stage
+ stage('SonarQube Analysis') {
+ steps {
+ withSonarQubeEnv('SonarQube') {
+ sh 'npm run sonar' // Run SonarQube analysis for code quality
+ }
+ }
+ }
+
+ // Start the application using PM2
+ stage('Start Application') {
+ steps {
+ script {
+ // Check if the application is already running with PM2
+ def appRunning = sh(script: 'pm2 list | grep "calculatorAPP"', returnStatus: true)
+
+ // If the app is running, stop it first
+ if (appRunning == 0) {
+ echo 'Application is already running. Stopping it first.'
+ sh 'pm2 stop calculatorAPP' // Stop the app to restart it
+ }
+
+ // Start the application with PM2, adding the -f flag to force re-execution if already running
+ echo 'Starting the application with PM2.'
+ sh 'pm2 start server.js --name "calculatorAPP" -f'
+ }
+ }
+ }
+
+ // Check the PM2 status to confirm the app is running
+ stage('Check Status') {
+ steps {
+ sh 'pm2 status' // Display the status of PM2 applications
+ }
+ }
+ }
+
+ // Notifications after the pipeline execution
+ post {
+ success {
+ slackSend(
+ channel: '#javanodeprojects',
+ color: 'good',
+ message: "✅ *Build Successful!*\nJob: ${env.JOB_NAME} #${env.BUILD_NUMBER}\nBranch: ${env.GIT_BRANCH}\nURL: ${env.BUILD_URL}"
+ )
+ }
+ failure {
+ slackSend(
+ channel: '#javanodeprojects',
+ color: 'danger',
+ message: "❌ *Build Failed!*\nJob: ${env.JOB_NAME} #${env.BUILD_NUMBER}\nBranch: ${env.GIT_BRANCH}\nURL: ${env.BUILD_URL}"
+ )
+ }
+ }
+}
diff --git a/package.json b/package.json
index 40b2243..c35cafc 100644
--- a/package.json
+++ b/package.json
@@ -1,20 +1,26 @@
{
- "name": "node-jenkins-project",
+ "name": "node-docker-ci-project",
"version": "1.0.0",
"description": "this project is for jenkins pipeline",
"main": "calculator.js",
"scripts": {
- "clean": "rm -rf node_modules package-lock.json coverage",
- "test": "nyc --reporter=lcov jest --coverage --collectCoverageFrom=**/*.js",
- "sonar": "npx sonar-scanner ",
+ "start": "node server.js",
+ "clean": "rm -rf node_modules package-lock.json coverage",
+ "test": "nyc --reporter=lcov jest --coverage --collectCoverageFrom=**/*.js",
+ "sonar": "sonar-scanner",
"coverage": "nyc --reporter=lcov --reporter=text npm test"
},
+ "jest-junit": {
+ "outputDirectory": "test-reports",
+ "outputName": "results.xml"
+},
"author": "",
"license": "ISC",
"devDependencies": {
"jest": "^29.7.0",
"nyc": "^17.1.0",
- "sonar-scanner": "^3.1.0"
+ "sonar-scanner": "^3.1.0",
+ "supertest": "^6.3.3"
},
"jest": {
"collectCoverage": true,
diff --git a/pom.xml b/pom.xml
deleted file mode 100644
index 1ba403d..0000000
--- a/pom.xml
+++ /dev/null
@@ -1,183 +0,0 @@
-
- 4.0.0
-
- com
- Declarative-Pipeline
- 3.1-SNAPSHOT
- war
- http://maven.apache.org
-
-
-17
-17
- http://192.168.33.11:9000
-sqa_1ea1d49ee057cab0d34953dcb1bfe79d78099b1d
-
-
-
-
-
-
-
- jakarta.servlet
- jakarta.servlet-api
- 5.0.0
- provided
-
-
-
-
-
- org.junit.jupiter
- junit-jupiter-api
- 5.9.2
- test
-
-
- org.junit.jupiter
- junit-jupiter-engine
- 5.9.2
- test
-
-
-
-
- org.mockito
- mockito-core
- 4.11.0
- test
-
-
-
-
- jakarta.servlet
- jakarta.servlet-api
- 5.0.0
- provided
-
-
-
-
-
-
-
- junit
- junit
- 4.13.2
- test
-
-
-
-
-
- javax.servlet.jsp
- javax.servlet.jsp-api
- 2.3.3
- provided
-
-
-
-
- javax.servlet
- jstl
- 1.2
-
-
-
-
- Pipeline-Project
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 3.8.1
-
- 8
- 8
-
-
-
-
-
- org.apache.maven.plugins
- maven-war-plugin
- 3.3.2
-
-
-
-
- org.apache.tomcat.maven
- tomcat7-maven-plugin
- 2.2
-
- http://localhost:8080/manager/text
- TomcatServer
- /war-project
-
-
-
-
- org.sonarsource.scanner.maven
- sonar-maven-plugin
- 3.9.1.2184
-
-
-
-
- org.jacoco
- jacoco-maven-plugin
- 0.8.11
-
-
- prepare-agent
-
- prepare-agent
-
-
-
- report
- verify
-
- report
-
-
-
-
-
-
-
-
-
-
-
-
-
- nexus
- http://65.0.104.25:8081/repository/release/
-
-
-
- nexus
- http://65.0.104.25:8081/repository/snapshot/
-
-
-
-
-
-
-
-
-
- org.sonarsource.scanner.maven
- sonar-maven-plugin
- 3.9.1.2184
-
-
-
-
-
-
-
diff --git a/public/index.html b/public/index.html
index 2a7452e..256c26f 100644
--- a/public/index.html
+++ b/public/index.html
@@ -1,37 +1,111 @@
-
-
- Calculator
-
+
+
+ Simple Calculator
+
- Calculator
-
-
-
- +
- -
- ×
- ÷
-
- Result: -
-
-
+
+
CALCULATOR
+
+
+
+ +
+ −
+ ×
+ ÷
+
+
+ Result: -
+
+
+
+
-
diff --git a/server.js b/server.js
index 71dbb6a..545345c 100644
--- a/server.js
+++ b/server.js
@@ -5,6 +5,9 @@ const Calculator = require('./calculator');
const app = express();
const calculator = new Calculator();
+// Disable Express 'X-Powered-By' header
+app.disable('x-powered-by');
+
// Serve static files (HTML, CSS, JS)
app.use(express.static(path.join(__dirname, 'public')));
@@ -35,7 +38,13 @@ app.get('/divide', (req, res) => {
// Start the server
const PORT = 3000;
-app.listen(PORT, '0.0.0.0', () => {
- console.log(`Server running at http://0.0.0.0:${PORT}`);
-});
+
+// Start the server only if this file is executed directly
+if (require.main === module) {
+ app.listen(PORT, '0.0.0.0', () => {
+ console.log(`Server running at http://0.0.0.0:${PORT}`);
+ });
+}
+
+module.exports = app;
diff --git a/server.test.js b/server.test.js
new file mode 100644
index 0000000..b6a41fe
--- /dev/null
+++ b/server.test.js
@@ -0,0 +1,36 @@
+const request = require('supertest');
+const express = require('express');
+const app = require('./server').default || require('./server');
+ // Ensure your server exports 'app'
+
+describe('Calculator API Endpoints', () => {
+ it('should add two numbers', async () => {
+ const res = await request(app).get('/add?a=5&b=3');
+ expect(res.statusCode).toBe(200);
+ expect(res.body.result).toBe(8);
+ });
+
+ it('should subtract two numbers', async () => {
+ const res = await request(app).get('/subtract?a=10&b=4');
+ expect(res.statusCode).toBe(200);
+ expect(res.body.result).toBe(6);
+ });
+
+ it('should multiply two numbers', async () => {
+ const res = await request(app).get('/multiply?a=6&b=2');
+ expect(res.statusCode).toBe(200);
+ expect(res.body.result).toBe(12);
+ });
+
+ it('should divide two numbers', async () => {
+ const res = await request(app).get('/divide?a=8&b=2');
+ expect(res.statusCode).toBe(200);
+ expect(res.body.result).toBe(4);
+ });
+
+ it('should return an error when dividing by zero', async () => {
+ const res = await request(app).get('/divide?a=5&b=0');
+ expect(res.statusCode).toBe(400);
+ expect(res.body.error).toBe("Cannot divide by zero");
+ });
+});
diff --git a/sonar-project.properties b/sonar-project.properties
index 583b03f..be753d6 100644
--- a/sonar-project.properties
+++ b/sonar-project.properties
@@ -5,7 +5,7 @@ sonar.sourceEncoding=UTF-8
sonar.sources=.
sonar.tests=.
sonar.test.inclusions=**/*test.js
-sonar.exclusions=node_modules/**,coverage/*
+sonar.exclusions=node_modules/**,coverage/**
sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.host.url=http://192.168.33.11:9000
-sonar.token=sqa_a17caa1c83667bf8d9f8700461c4538f32082fc2
+
diff --git a/src/main/java/com/app/example/HelloServlet.java b/src/main/java/com/app/example/HelloServlet.java
deleted file mode 100644
index b288d9f..0000000
--- a/src/main/java/com/app/example/HelloServlet.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.app.example;
-
-import java.io.IOException;
-import jakarta.servlet.ServletException;
-import jakarta.servlet.annotation.WebServlet;
-import jakarta.servlet.http.HttpServlet;
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpServletResponse;
-
-@WebServlet("/hello")
-public class HelloServlet extends HttpServlet {
- protected void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- response.getWriter().println("Hello from Servlet!");
- }
-}
diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp
deleted file mode 100644
index 3109b8a..0000000
--- a/src/main/webapp/index.jsp
+++ /dev/null
@@ -1,943 +0,0 @@
-
-<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
-
-
-
-
- Deepak Sagar - Portfolio
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Hi, I'm Deepak Sagar
-
- DevOps Engineer
-
-
- Automating and optimizing infrastructure with expertise in
- CI/CD, cloud technologies, and containerization. Bridging the
- gap between development and operations.
-
-
-
- Download CV
-
-
- Contact Me
-
-
-
-
-
-
-
-
-
-
-
-
About Me
-
-
-
-
-
- Skills
- SQL,Linux,AWS,DevOps,Jenkins,Docker,Python,CI/Cd,Kubernetes
-
-
- Language
- English, hindi
-
-
- Awards & Honor
- Secured top percentile in JEE Advanced
-
-
- Test score
- JEE Advance ( 1700 ), JEE Mains ( 2700 )
-
-
- Total Experience
- 1 Year
-
-
- Company Name
- NIT Raipur
-
-
- Duration
- June 2022 - January 2024
-
-
- Job Profile
- Intern
-
-
- Annual Salary
- 10 Lakh(s)
-
-
-
-
-
-
- Full Stack Developer & Cloud Engineer
-
-
- With over 8 years of experience in web development, I've had the
- privilege of working with diverse teams and clients across
- various industries. My passion lies in creating intuitive,
- user-centric applications that solve real-world problems.
-
-
-
-
Location
-
MOradabad,UP
-
-
-
Experience
-
8+ Years
-
-
-
Projects
-
100+ Completed
-
-
-
Clients
-
50+ Satisfied
-
-
-
- Download Resume
-
-
-
-
-
-
-
-
- Skills & Expertise
-
-
-
-
Cloud & Infrastructure
-
-
-
-
- Terraform
- 90%
-
-
-
-
-
- Kubernetes
- 85%
-
-
-
-
-
-
-
CI/CD & Automation
-
-
-
-
- GitLab CI
- 85%
-
-
-
-
-
-
-
-
Monitoring & Security
-
-
-
- Prometheus
- 85%
-
-
-
-
-
- ELK Stack
- 80%
-
-
-
-
-
- Security Tools
- 75%
-
-
-
-
-
-
-
-
-
-
-
Portfolio
-
-
-
- All
-
-
- Web Apps
-
-
- Mobile Apps
-
-
- UI/UX
-
-
-
-
-
-
-
-
-
- Cloud Migration Project
-
-
- Migrated legacy systems to microservices architecture on AWS
-
-
-
-
-
-
-
-
-
-
- Social Connect
-
-
- A modern social networking platform
-
-
-
-
-
-
-
-
-
-
- E-Commerce Platform
-
-
- A full-featured online shopping platform
-
-
-
-
-
-
-
-
-
-
-
- Professional Experience
-
-
-
-
-
-
-
-
- Senior DevOps Engineer
-
-
Google Cloud
-
2021 - Present
-
-
-
-
-
-
- Led infrastructure automation initiatives and implemented
- GitOps practices. Reduced deployment time by 60% and
- achieved 99.99% uptime across production services. Managed
- multi-cloud Kubernetes clusters serving millions of users.
-
-
-
-
-
-
-
-
- DevOps Engineer
-
-
AWS
-
2018 - 2021
-
-
-
-
-
-
- Designed and implemented CI/CD pipelines using AWS
- services. Automated infrastructure deployment with
- Terraform and CloudFormation. Reduced infrastructure costs
- by 35% through optimization.
-
-
-
-
-
-
-
-
- Systems Engineer
-
-
Microsoft Azure
-
2016 - 2018
-
-
-
-
-
-
- Managed large-scale cloud infrastructure and implemented
- monitoring solutions. Set up automated disaster recovery
- procedures and reduced system downtime by 75%.
-
-
-
-
-
-
-
-
-
-
-
- Client Testimonials
-
-
-
-
-
-
-
Sarah Johnson
-
CEO at TechCorp
-
-
-
- "James delivered exceptional results for our project. His
- technical expertise and attention to detail made him a valuable
- asset to our team."
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Michael Chen
-
CTO at StartupX
-
-
-
- "Working with Deepak was a pleasure. He brought innovative
- solutions to our challenges and consistently delivered
- high-quality work."
-
-
-
-
-
-
-
-
-
-
-
-
-
-
David Smith
-
Product Manager at InnovateCo
-
-
-
- "Deepak's technical skills and problem-solving abilities are
- outstanding. He's a great communicator and team player."
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
James Wilson
-
- Crafting digital experiences with passion and precision.
-
-
-
-
-
-
Newsletter
-
-
-
- Subscribe
-
-
-
-
-
-
- © 2024 James Wilson. All rights reserved.
-
-
-
-
-
-
-
-
-
diff --git a/src/test/java/com/app/example/HelloServletTest.java b/src/test/java/com/app/example/HelloServletTest.java
deleted file mode 100644
index 6b7deea..0000000
--- a/src/test/java/com/app/example/HelloServletTest.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package com.app.example;
-
-import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpServletResponse;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-
-import static org.junit.jupiter.api.Assertions.*;
-import static org.mockito.Mockito.*;
-
-public class HelloServletTest {
-
- @Test
- void testDoGet() throws Exception {
- // Mock HttpServletRequest and HttpServletResponse
- HttpServletRequest request = mock(HttpServletRequest.class);
- HttpServletResponse response = mock(HttpServletResponse.class);
-
- // Capture response output
- StringWriter stringWriter = new StringWriter();
- PrintWriter writer = new PrintWriter(stringWriter);
- when(response.getWriter()).thenReturn(writer);
-
- // Create instance of servlet and call doGet
- HelloServlet servlet = new HelloServlet();
- servlet.doGet(request, response);
-
- // Verify the response output
- writer.flush();
- assertEquals("Hello from Servlet!", stringWriter.toString().trim());
- }
-}