43 lines
959 B
JavaScript
43 lines
959 B
JavaScript
// static variables and imports
|
|
import express from "express";
|
|
import {
|
|
createUser,
|
|
deleteUser,
|
|
getAllUsers,
|
|
loginUser,
|
|
updateUser,
|
|
} from "../user-mgmt_backend/database.js";
|
|
import dotenv from "dotenv";
|
|
import path from "path";
|
|
import { fileURLToPath } from "url";
|
|
const app = express();
|
|
dotenv.config();
|
|
const port = 40001;
|
|
|
|
app.use(express.json());
|
|
app.use(express.static("public"));
|
|
|
|
app.use(express.urlencoded({ extended: true }));
|
|
app.set("view engine", "ejs");
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
app.listen(port, () => {
|
|
console.log(`Server is running on http://localhost:${port}`);
|
|
});
|
|
|
|
|
|
|
|
// -- here comes the main code --
|
|
app.get("/", (req, res) => {
|
|
res.render("index.ejs");
|
|
});
|
|
|
|
// error handling code
|
|
app.use((err, req, res, next) => {
|
|
// Log the error stack and send a generic error response
|
|
console.error(err.stack);
|
|
res.status(500).send("Something broke!");
|
|
});
|