From 57d1b4fc4a6f6b51e7aeb5b3511e21467fc66ddb Mon Sep 17 00:00:00 2001 From: mohamedyhyamostafa-tech Date: Wed, 8 Oct 2025 21:26:11 +0300 Subject: [PATCH] Update app.js --- app.js | 335 +++++++++++++++++++++++++++------------------------------ 1 file changed, 156 insertions(+), 179 deletions(-) diff --git a/app.js b/app.js index b471157..6aa8fd3 100644 --- a/app.js +++ b/app.js @@ -1,182 +1,159 @@ -const { MongoClient } = require("mongodb"); - -async function run() { - // TODO: - // Replace the placeholder connection string below with your - // Altas cluster specifics. Be sure it includes - // a valid username and password! Note that in a production environment, - // you do not want to store your password in plain-text here. - const uri = - "mongodb+srv://:@?retryWrites=true&w=majority"; - - // The MongoClient is the object that references the connection to our - // datastore (Atlas, for example) - const client = new MongoClient(uri); - - // The connect() method does not attempt a connection; instead it instructs - // the driver to connect using the settings provided when a connection - // is required. - await client.connect(); - - // Provide the name of the database and collection you want to use. - // If the database and/or collection do not exist, the driver and Atlas - // will create them automatically when you first write data. - const dbName = "myDatabase"; - const collectionName = "recipes"; - - // Create references to the database and collection in order to run - // operations on them. - const database = client.db(dbName); - const collection = database.collection(collectionName); - - /* - * *** INSERT DOCUMENTS *** - * - * You can insert individual documents using collection.insert(). - * In this example, we're going to create four documents and then - * insert them all in one call with collection.insertMany(). - */ - - const recipes = [ - { - name: "elotes", - ingredients: [ - "corn", - "mayonnaise", - "cotija cheese", - "sour cream", - "lime", - ], - prepTimeInMinutes: 35, - }, - { - name: "loco moco", - ingredients: [ - "ground beef", - "butter", - "onion", - "egg", - "bread bun", - "mushrooms", - ], - prepTimeInMinutes: 54, - }, - { - name: "patatas bravas", - ingredients: [ - "potato", - "tomato", - "olive oil", - "onion", - "garlic", - "paprika", - ], - prepTimeInMinutes: 80, - }, - { - name: "fried rice", - ingredients: [ - "rice", - "soy sauce", - "egg", - "onion", - "pea", - "carrot", - "sesame oil", - ], - prepTimeInMinutes: 40, - }, - ]; - - try { - const insertManyResult = await collection.insertMany(recipes); - console.log(`${insertManyResult.insertedCount} documents successfully inserted.\n`); - } catch (err) { - console.error(`Something went wrong trying to insert the new documents: ${err}\n`); - } - - /* - * *** FIND DOCUMENTS *** - * - * Now that we have data in Atlas, we can read it. To retrieve all of - * the data in a collection, we call Find() with an empty filter. - * The Builders class is very helpful when building complex - * filters, and is used here to show its most basic use. - */ - - const findQuery = { prepTimeInMinutes: { $lt: 45 } }; - - try { - const cursor = await collection.find(findQuery).sort({ name: 1 }); - await cursor.forEach(recipe => { - console.log(`${recipe.name} has ${recipe.ingredients.length} ingredients and takes ${recipe.prepTimeInMinutes} minutes to make.`); - }); - // add a linebreak - console.log(); - } catch (err) { - console.error(`Something went wrong trying to find the documents: ${err}\n`); - } - - // We can also find a single document. Let's find the first document - // that has the string "potato" in the ingredients list. - const findOneQuery = { ingredients: "potato" }; - - try { - const findOneResult = await collection.findOne(findOneQuery); - if (findOneResult === null) { - console.log("Couldn't find any recipes that contain 'potato' as an ingredient.\n"); +const html = ` + + + + + +🐍 Alzaeem Tech AI - Snake Game + + + +

🤖 Alzaeem Tech AI Snake Game

+ +
Score: 0
+
+
+ + +
+ +
+ + + + +`; + +module.exports = (req, res) => { + res.setHeader("Content-Type", "text/html"); + res.end(html); +};