diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f37143a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM node + +ENV MONGO_DB_USERNAME=admin \ + MONGO_DB_PWD=qwerty + +WORKDIR /testapp + +COPY . . + +# 👇 This is what's missing +RUN npm install + +CMD ["node", "server.js"] diff --git a/mongodb.yaml b/mongodb.yaml new file mode 100644 index 0000000..2228055 --- /dev/null +++ b/mongodb.yaml @@ -0,0 +1,19 @@ +version: "3.8" + +services: + mongo: + image: mongo + ports: + - "27017:27017" + environment: + MONGO_INITDB_ROOT_USERNAME: admin + MONGO_INITDB_ROOT_PASSWORD: qwerty + + mongo-express: + image: mongo-express + ports: + - "8081:8081" + environment: + ME_CONFIG_MONGODB_ADMINUSERNAME: admin + ME_CONFIG_MONGODB_ADMINPASSWORD: qwerty + ME_CONFIG_MONGODB_URL: mongodb://admin:qwerty@mongo:27017/ diff --git a/server.js b/server.js index d869597..230ef82 100644 --- a/server.js +++ b/server.js @@ -1,4 +1,5 @@ const express = require("express"); + const app = express(); const path = require("path"); const MongoClient = require("mongodb").MongoClient; @@ -7,11 +8,13 @@ const PORT = 5050; app.use(express.urlencoded({ extended: true })); app.use(express.static("public")); + const MONGO_URL = "mongodb://admin:qwerty@localhost:27017"; + const client = new MongoClient(MONGO_URL); //GET all users -app.get("/getUsers", async (req, res) => { +app.get("/getUsers" ,async (req, res) => { await client.connect(URL); console.log('Connected successfully to server'); diff --git a/ubuntu@35.154.172.157/nodejs-apna-college/mongodb.yaml b/ubuntu@35.154.172.157/nodejs-apna-college/mongodb.yaml new file mode 100644 index 0000000..a9f260f --- /dev/null +++ b/ubuntu@35.154.172.157/nodejs-apna-college/mongodb.yaml @@ -0,0 +1,19 @@ +version: "3.8" + +services: + mongo: + image:mongo + ports: + - 27017:27017 + environment: + MONGO_INITDB_ROOT_USERNAME:admin + MONGO_INITDB_ROOT_PASSWORD:qwerty + +mongo-express: + image:mongo-express + ports: + -8081:8081 + environment: + ME_CONFIG_MONGODB_ADMINUSERNAME:admin + ME_CONFIG_MONGODB_ADMINPASSWORD:qwerty + ME_CONFIG_MONGODB_URL:mongodb://admin:qwerty@mongo:27017/