Commit a81cce1d authored by Asad ullah khan's avatar Asad ullah khan

initial

parents
Pipeline #1883 passed with stage
in 0 seconds
node_modules
\ No newline at end of file
PORT=4005
#DB_URL=mongodb://asad:asad123@192.168.18.5:32000/my-demo-project?retryWrites=true&w=majority
DB_URL=mongodb://asad:asad123@192.168.18.5:32000/test-database?retryWrites=true&w=majority
#mongodb://asad:asad123@mongo-svc/my-demo-project?retryWrites=true&w=majority"
node_modules
\ No newline at end of file
FROM node:12-alpine3.14
WORKDIR /app
COPY . /app
COPY package.json /app
RUN npm i
ENV PORT 4005
EXPOSE 4005
CMD node index.js
pipeline {
environment {
imageRepo = "asadullahkhan/poc-backend"
registryCredential = 'docker'
dockerImage = ''
}
agent any
stages {
stage('Cloning Git') {
steps {
git([url: 'https://github.com/AsadUkh/app-code-backend.git', branch: 'master'])
}
}
stage('Build application') {
steps {
sh "npm install"
}
}
stage('Building Docker image') {
steps{
script {
dockerImage = docker.build("$imageRepo:${env.BUILD_ID}")
}
}
}
stage('Push Image to Docker Hub') {
steps{
script {
dockerImage.push()
}
}
}
// stage('Remove Unused docker image') {
// steps{
// sh "docker rmi $imagename:$BUILD_NUMBER"
// sh "docker rmi $imagename:latest"
// }
// }
}
}
\ No newline at end of file
const path = require('path');
const express = require('express');
const mongoose = require('mongoose');
const UserModel = require('./model/users');
require('dotenv').config();
const app = express();
const cors = require('cors');
app.use(cors())
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
// app.get('/users', (req,res,send) => {
// UserModel.find({}).then(result => {
// console.log(result)
// return res.render('users', { result });
// })
// })
app.get('/users', (req,res,send) => {
UserModel.find({}).then(result => {
return res.status(200).json(result);
}).catch(err => {
console.log(err);
return res.status(500).send('something went wrong');
})
})
app.get('/', (req,res,send) => {
return res.render('welcome');
})
const db_url= process.env.DB_URL;
console.log(db_url);
mongoose.connect(db_url, () => {
app.listen(process.env.PORT || 3333, () => {
console.log('Server started!!');
})
});
const db = mongoose.connection;
db.on("error", console.error.bind(console, "connection error: "));
db.once("open", function () {
console.log("Connected successfully");
});
const mongoose = require('mongoose');
const UserSchema = new mongoose.Schema({
screenName: String,
firstName: String,
lastName: String,
email: String,
password: String,
confirmPassword : String
});
module.exports = mongoose.model('user', UserSchema);
\ No newline at end of file
This diff is collapsed.
{
"name": "poc",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js",
"start:dev": "nodemon index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^16.0.0",
"ejs": "^3.1.6",
"express": "^4.17.3",
"mongoose": "^6.2.3"
}
}
<!DOCTYPE html>
<html>
<head>
<title>View Engine Demo</title>
</head>
<body>
<h1>List of Users</h1>
<ul>
<% for(var user of result){ %>
<li>
<span><%= user.firstName %></span>
<span> | </span>
<span><%= user.lastName %></span>
<span> | </span>
<span><%= user.email %></span>
<span> | </span>
<span><%= user.screenName %></span>
</li>
<% } %>
</ul>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title>Welcome to my poc Application</title>
</head>
<body>
<h1> Welcome to my poc application</h1>
<a href="/users">Go to users List</a>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment