-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump mongoose version and add server response to the root path
- Loading branch information
AntonellaMorittu
authored and
AntonellaMorittu
committed
May 13, 2024
1 parent
0966af5
commit 57219ae
Showing
3 changed files
with
132 additions
and
78 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,34 @@ | ||
// Import necessary libraries and modules | ||
import express from "express"; // Import the Express.js framework | ||
import cors from "cors"; // Import the CORS middleware | ||
import dotenv from "dotenv"; // Import dotenv for environment variables | ||
dotenv.config(); // Load environment variables from the .env file | ||
import taskRoutes from "./routes/taskRoutes"; // Import custom task controlled-routes | ||
import userRoutes from "./routes/userRoutes"; // Import custom user routes | ||
import { connectDB } from "./config/db"; // Import database connection function (not used here) | ||
import express from "express" // Import the Express.js framework | ||
import cors from "cors" // Import the CORS middleware | ||
import dotenv from "dotenv" // Import dotenv for environment variables | ||
dotenv.config() // Load environment variables from the .env file | ||
import taskRoutes from "./routes/taskRoutes" // Import custom task controlled-routes | ||
import userRoutes from "./routes/userRoutes" // Import custom user routes | ||
import { connectDB } from "./config/db" // Import database connection function (not used here) | ||
|
||
// Defines the port the app will run on. Defaults to 8080, but can be overridden | ||
const port = process.env.PORT; // Set the port number for the server | ||
const app = express(); // Create an instance of the Express application | ||
const port = process.env.PORT // Set the port number for the server | ||
const app = express() // Create an instance of the Express application | ||
|
||
// Add middlewares to enable cors and json body parsing | ||
app.use(cors()); // Enable CORS (Cross-Origin Resource Sharing) | ||
app.use(express.json()); // Parse incoming JSON data | ||
app.use(express.urlencoded({ extended: false })); // Parse URL-encoded data | ||
app.use(cors()) // Enable CORS (Cross-Origin Resource Sharing) | ||
app.use(express.json()) // Parse incoming JSON data | ||
app.use(express.urlencoded({ extended: false })) // Parse URL-encoded data | ||
|
||
// Use the routes for handling API requests | ||
// ROUTES - These routes USE controller functions ;) | ||
app.use(taskRoutes); // Use the task-controlled routes for task-related requests | ||
app.use(userRoutes); // Use the user-controlled routes for user-related requests | ||
app.use(taskRoutes) // Use the task-controlled routes for task-related requests | ||
app.use(userRoutes) // Use the user-controlled routes for user-related requests | ||
|
||
// Connection to the database through Mongoose | ||
connectDB(); | ||
connectDB() | ||
|
||
app.get("/", (req, res) => { | ||
res.send("Hello World!") | ||
}) | ||
|
||
// Start the server and listen for incoming requests on the specified port | ||
app.listen(port, () => { | ||
console.log(`Server running on http://localhost:${port}`); // Display a message when the server is successfully started | ||
}); | ||
console.log(`Server running on http://localhost:${port}`) // Display a message when the server is successfully started | ||
}) |