diff --git a/backend/Node.js b/backend/Node.js index c921bd2..9f013fb 100755 --- a/backend/Node.js +++ b/backend/Node.js @@ -1,13 +1,10 @@ -Sure! Here's the code for the `./backend/Node.js` file: - -```javascript // Import required modules -const express = require('express'); -const bodyParser = require('body-parser'); -const mongoose = require('mongoose'); +const express = require("express"); +const bodyParser = require("body-parser"); +const mongoose = require("mongoose"); // Create an instance of Express -const app = express(); +const expressApp = express(); // Set up body-parser middleware app.use(bodyParser.urlencoded({ extended: false })); @@ -16,42 +13,40 @@ app.use(bodyParser.json()); // Connect to MongoDB database /** * Connect to the MongoDB database. - * + * * @returns {Promise} A promise that resolves when the connection is successful. */ -mongoose.connect('mongodb://localhost/mydatabase', { useNewUrlParser: true, useUnifiedTopology: true }) +mongoose + .connect("mongodb://localhost/mydatabase", { + useNewUrlParser: true, + useUnifiedTopology: true, + }) .then(() => { - console.log('Connected to MongoDB'); + console.log("Connected to MongoDB"); }) .catch((error) => { - console.error('Error connecting to MongoDB:', error); + console.error("Error connecting to MongoDB:", error); }); // Define routes /** * Handle GET request for the root URL ("/"). - * + * * @param {Object} req - The request object. * @param {Object} res - The response object. * @returns {void} */ -app.get('/', (req, res) => { - res.send('Hello, world!'); +expressApp.get("/", (req, res) => { + res.send("Hello, world!"); }); // Start the server -const port = process.env.PORT || 3000; +const serverPort = process.env.PORT || 3000; /** * Start the server and listen on the specified port. - * + * * @returns {void} */ -app.listen(port, () => { - console.log(`Server is running on port ${port}`); +expressApp.listen(serverPort, () => { + console.log(`Server is running on port ${serverPort}`); }); - -This code sets up a basic Node.js server using Express framework. It includes the necessary imports, middleware setup, MongoDB connection, and a simple route for the root URL ("/"). The server listens on the specified port (default is 3000) and logs a message when it starts running. - -Please note that you may need to modify the MongoDB connection URL (`mongodb://localhost/mydatabase`) based on your specific MongoDB setup. - -Let me know if you need any further assistance! \ No newline at end of file diff --git a/database/MongoDB b/database/MongoDB index a923661..0ad1ffd 100755 --- a/database/MongoDB +++ b/database/MongoDB @@ -6,17 +6,17 @@ * @param {Object} res - The response object. * @returns {void} */ -app.get('/', (req, res) => { +expressApp.get('/', (req, res) => { res.send('Hello, world!'); }); // Start the server -const port = process.env.PORT || 3000; +const serverPort = process.env.PORT || 3000; /** * Start the server and listen on the specified port. * * @returns {void} */ -app.listen(port, () => { - console.log(`Server is running on port ${port}`); +expressApp.listen(serverPort, () => { + console.log(`Server is running on port ${serverPort}`); });