1
0
Fork 0
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:
Sohaib Manah 2023-03-24 16:02:31 +00:00
parent e6b1d2755f
commit c5c2efb203
62 changed files with 12812 additions and 0 deletions

View file

@ -0,0 +1 @@
MONGODB_URI=mongodb://mongo:27017

View file

@ -0,0 +1,2 @@
node_modules
.env

View file

@ -0,0 +1,13 @@
FROM node:19-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
EXPOSE 5000
COPY . .
CMD ["npm","start"]

View 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();

File diff suppressed because it is too large Load diff

View 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"
}

View 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");
});