Skip to content

Commit

Permalink
MongoDB connected to backend
Browse files Browse the repository at this point in the history
  • Loading branch information
luke1212 committed May 26, 2023
1 parent 33292fa commit c1b345a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ testem.log
Thumbs.db
environment.ts
environment.ts
backend/environment.js
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cSpell.words": ["openai"]
}
25 changes: 25 additions & 0 deletions backend/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
const express = require("express");
const bodyParser = require("body-parser");

const environment = require("./environment");
const app = express();
const { MongoClient, ServerApiVersion } = require('mongodb');
const uri = environment.mongoDB.MONGODB_URI;
// Create a MongoClient with a MongoClientOptions object to set the Stable API version
const client = new MongoClient(uri, {
serverApi: {
version: ServerApiVersion.v1,
strict: true,
deprecationErrors: true,
}
});

async function run() {
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();
}
}
run().catch(console.dir);

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"bootstrap": "^5.2.3",
"bootstrap-icons": "^1.10.5",
"express": "^4.18.2",
"mongodb": "^5.5.0",
"mongoose": "^7.2.0",
"openai": "^3.2.1",
"rxjs": "~7.8.0",
Expand Down

0 comments on commit c1b345a

Please sign in to comment.