mirror of
https://github.com/docker/awesome-compose.git
synced 2025-04-29 15:48:03 +02:00
add mongodb-angular-expressjs-nodejs docker sample
Signed-off-by: Sohaib Manah <souhaibemanah@gmail.com>
This commit is contained in:
parent
e6b1d2755f
commit
c5c2efb203
62 changed files with 12812 additions and 0 deletions
1
mongodb-angular-expressjs-nodejs/backend/.env.example
Normal file
1
mongodb-angular-expressjs-nodejs/backend/.env.example
Normal file
|
@ -0,0 +1 @@
|
|||
MONGODB_URI=mongodb://mongo:27017
|
2
mongodb-angular-expressjs-nodejs/backend/.gitignore
vendored
Normal file
2
mongodb-angular-expressjs-nodejs/backend/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
node_modules
|
||||
.env
|
13
mongodb-angular-expressjs-nodejs/backend/Dockerfile
Normal file
13
mongodb-angular-expressjs-nodejs/backend/Dockerfile
Normal file
|
@ -0,0 +1,13 @@
|
|||
FROM node:19-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package*.json ./
|
||||
|
||||
RUN npm install
|
||||
|
||||
EXPOSE 5000
|
||||
|
||||
COPY . .
|
||||
|
||||
CMD ["npm","start"]
|
29
mongodb-angular-expressjs-nodejs/backend/db/mongodb.js
Normal file
29
mongodb-angular-expressjs-nodejs/backend/db/mongodb.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
import { MongoClient, ServerApiVersion } from "mongodb";
|
||||
import dotenv from "dotenv";
|
||||
dotenv.config();
|
||||
|
||||
// Create a MongoClient with a MongoClientOptions object to set the Stable API version
|
||||
const client = new MongoClient(
|
||||
process.env.MONGODB_URI || "mongodb://mongo:27017",
|
||||
{
|
||||
serverApi: {
|
||||
version: ServerApiVersion.v1,
|
||||
strict: true,
|
||||
deprecationErrors: true,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
try {
|
||||
// Connect the client to the server (optional starting in v4.7)
|
||||
await client.connect();
|
||||
|
||||
// Send a ping to confirm a successful connection
|
||||
await client.db("admin").command({ ping: 1 });
|
||||
console.log("Pinged your deployment. You successfully connected to MongoDB!");
|
||||
} finally {
|
||||
// Ensures that the client will close when you finish/error
|
||||
await client.close();
|
||||
}
|
||||
|
||||
export default client.connect();
|
1117
mongodb-angular-expressjs-nodejs/backend/package-lock.json
generated
Normal file
1117
mongodb-angular-expressjs-nodejs/backend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
19
mongodb-angular-expressjs-nodejs/backend/package.json
Normal file
19
mongodb-angular-expressjs-nodejs/backend/package.json
Normal file
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"name": "backend",
|
||||
"version": "1.0.0",
|
||||
"description": "Running Node.js and Express.js on Docker",
|
||||
"main": "server.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "nodemon server.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.0.3",
|
||||
"express": "^4.18.2",
|
||||
"mongodb": "^5.1.0",
|
||||
"nodemon": "^2.0.22"
|
||||
},
|
||||
"author": "",
|
||||
"license": "MIT"
|
||||
}
|
14
mongodb-angular-expressjs-nodejs/backend/server.js
Normal file
14
mongodb-angular-expressjs-nodejs/backend/server.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
import express from "express";
|
||||
import client from "./db/mongodb.js";
|
||||
const app = express();
|
||||
import cors from "cors";
|
||||
|
||||
app.use(cors("http://localhost:4200"));
|
||||
|
||||
app.get("/", function (req, res) {
|
||||
res.status(200).json({ message: "Hello World" });
|
||||
});
|
||||
|
||||
app.listen(5000, function () {
|
||||
console.log("Web application is listening on port 5000");
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue