Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit 0743099d authored by 65160024's avatar 65160024
Browse files

Update file server.js

parent 453c2da2
No related branches found
No related tags found
No related merge requests found
...@@ -15,6 +15,15 @@ const db = mysql.createConnection({ ...@@ -15,6 +15,15 @@ const db = mysql.createConnection({
database: process.env.DB_NAME, database: process.env.DB_NAME,
}); });
// เชื่อมต่อกับฐานข้อมูล
db.connect((err) => {
if (err) {
console.error("❌ ไม่สามารถเชื่อมต่อฐานข้อมูล:", err);
return;
}
console.log("✅ เชื่อมต่อฐานข้อมูลสำเร็จ!");
});
// Middleware // Middleware
app.use(morgan("dev")); app.use(morgan("dev"));
app.use(express.json({ limit: "20mb" })); app.use(express.json({ limit: "20mb" }));
...@@ -31,13 +40,8 @@ readdirSync(routesPath).map((file) => { ...@@ -31,13 +40,8 @@ readdirSync(routesPath).map((file) => {
app.use("/api", require(routePath)); app.use("/api", require(routePath));
}); });
app.listen(3000, () => console.log("Server is running on port 3000")); app.get('/', (req, res) => {
res.send('Hello World!')
})
// เชื่อมต่อกับฐานข้อมูล app.listen(3000, () => console.log("Server is running on port 3000"));
db.connect((err) => { \ No newline at end of file
if (err) {
console.error("❌ ไม่สามารถเชื่อมต่อฐานข้อมูล:", err);
return;
}
console.log("✅ เชื่อมต่อฐานข้อมูลสำเร็จ!");
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment