-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
32 lines (26 loc) · 857 Bytes
/
Copy pathserver.js
File metadata and controls
32 lines (26 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require("dotenv").config();
const express = require("express");
const connectDB = require("./config/connection");
const routes = require("./routes/routes");
const app = express();
const PORT = process.env.PORT || 3001;
/**
* MIDDLEWARE
* These parse incoming request data so they are available under req.body.
*/
app.use(express.urlencoded({ extended: true })); // Parses URL-encoded data (from HTML forms)
app.use(express.json()); // Parses JSON data (from API requests)
/**
* API ROUTES
* Prefixing with '/api/users', ensure all backend routes (e.g., /api/users/notes)
*/
app.use("/api", routes);
/**
* DATABASE INITIALIZATION
* Waiting for a successful MongoDB connection before starting the server.
*/
connectDB().then(() => {
app.listen(PORT, () => {
console.log(`Server is running at http://localhost:${PORT}`);
});
});