Skip to content

Commit 093d127

Browse files
committed
ma
1 parent 9f7e8e6 commit 093d127

File tree

6 files changed

+142
-33
lines changed

6 files changed

+142
-33
lines changed

.devcontainer/Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM mcr.microsoft.com/devcontainers/javascript-node:1-22-bookworm
2+
3+
# Install MongoDB command line tools - though mongo-database-tools not available on arm64
4+
ARG MONGO_TOOLS_VERSION=6.0
5+
RUN . /etc/os-release \
6+
&& curl -sSL "https://www.mongodb.org/static/pgp/server-${MONGO_TOOLS_VERSION}.asc" | gpg --dearmor > /usr/share/keyrings/mongodb-archive-keyring.gpg \
7+
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/mongodb-archive-keyring.gpg] http://repo.mongodb.org/apt/debian ${VERSION_CODENAME}/mongodb-org/${MONGO_TOOLS_VERSION} main" | tee /etc/apt/sources.list.d/mongodb-org-${MONGO_TOOLS_VERSION}.list \
8+
&& apt-get update && export DEBIAN_FRONTEND=noninteractive \
9+
&& apt-get install -y mongodb-mongosh \
10+
&& if [ "$(dpkg --print-architecture)" = "amd64" ]; then apt-get install -y mongodb-database-tools; fi \
11+
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*
12+
13+
# [Optional] Uncomment this section to install additional OS packages.
14+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
15+
# && apt-get -y install --no-install-recommends <your-package-list-here>
16+
17+
# [Optional] Uncomment if you want to install an additional version of node using nvm
18+
# ARG EXTRA_NODE_VERSION=10
19+
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"
20+
21+
# [Optional] Uncomment if you want to install more global node modules
22+
# RUN su node -c "npm install -g <your-package-list-here>"
23+
24+
25+

.devcontainer/devcontainer.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/javascript-node-mongo
3+
{
4+
"name": "Node.js & Mongo DB",
5+
"dockerComposeFile": "docker-compose.yml",
6+
"service": "app",
7+
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
8+
9+
// Features to add to the dev container. More info: https://containers.dev/features.
10+
// "features": {},
11+
12+
// Configure tool-specific properties.
13+
"customizations": {
14+
// Configure properties specific to VS Code.
15+
"vscode": {
16+
// Add the IDs of extensions you want installed when the container is created.
17+
"extensions": [
18+
"mongodb.mongodb-vscode",
19+
"streetsidesoftware.code-spell-checker"
20+
]
21+
}
22+
},
23+
"features": {
24+
"ghcr.io/devcontainers-extra/features/jshint:2": {}
25+
},
26+
27+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
28+
// "forwardPorts": [3000, 27017],
29+
30+
// Use 'postCreateCommand' to run commands after the container is created.
31+
"postCreateCommand": "npm install"
32+
33+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
34+
35+
}

.devcontainer/docker-compose.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
version: '3.8'
2+
3+
services:
4+
app:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
volumes:
9+
- ../..:/workspaces:cached
10+
11+
# Overrides default command so things don't shut down after the process ends.
12+
command: sleep infinity
13+
14+
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
15+
network_mode: service:db
16+
17+
# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
18+
# (Adding the "ports" property to this file will not forward from a Codespace.)
19+
20+
db:
21+
image: mongo:latest
22+
restart: unless-stopped
23+
volumes:
24+
- mongodb-data:/data/db
25+
26+
# Uncomment to change startup options
27+
# environment:
28+
# MONGO_INITDB_ROOT_USERNAME: root
29+
# MONGO_INITDB_ROOT_PASSWORD: example
30+
# MONGO_INITDB_DATABASE: your-database-here
31+
32+
# Add "forwardPorts": ["27017"] to **devcontainer.json** to forward MongoDB locally.
33+
# (Adding the "ports" property to this file will not forward from a Codespace.)
34+
35+
volumes:
36+
mongodb-data:

app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const mongoose = require("mongoose");
2727
mongoose.set("strictQuery", false);
2828

2929
const dev_db_url =
30-
"mongodb+srv://cooluser:coolpassword@cluster0.cojoign.mongodb.net/local_library?retryWrites=true&w=majority&appName=Cluster0";
30+
"mongodb://localhost:27017/local_library"
3131
const mongoDB = process.env.MONGODB_URI || dev_db_url;
3232

3333
main().catch((err) => console.log(err));

package-lock.json

Lines changed: 43 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"serverstart": "DEBUG=express-locallibrary-tutorial:* npm run devstart"
1212
},
1313
"dependencies": {
14+
"async": "^3.2.6",
1415
"compression": "^1.7.4",
1516
"cookie-parser": "^1.4.6",
1617
"debug": "^4.3.5",
@@ -21,7 +22,7 @@
2122
"helmet": "^7.1.0",
2223
"http-errors": "^2.0.0",
2324
"luxon": "^3.4.4",
24-
"mongoose": "^8.9.5",
25+
"mongoose": "^8.15.0",
2526
"morgan": "^1.10.0",
2627
"pug": "^3.0.3"
2728
},

0 commit comments

Comments
 (0)