-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
33 lines (29 loc) · 952 Bytes
/
Copy pathapp.js
File metadata and controls
33 lines (29 loc) · 952 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
33
import connection_db from "./database/connectionDB.js";
import bookModel from "./models/bookModel.js";
import express from "express";
import bookRoutes from "./routes/bookRoutes.js";
import cors from "cors";
const port = 4000;
export const app = express(); // common.js no exporta al final
// middleware
app.get("/hola", (req, res) => {
res.send("Hola primera api");
});
app.use(cors());
app.use(express.json());
app.use("/books", bookRoutes);
try {
await connection_db.authenticate();
console.log("Conexión a la base de datos establecida correctamente.");
// Sincroniza el modelo con la base de datos
await bookModel.sync({ force: false });
console.log('La tabla "books" ha sido sincronizada.');
} catch (error) {
console.error(
"Error al conectar a la base de datos o al agregar libros:",
error
);
}
export const server = app.listen(4000, () => {
console.log(`Server is running on http://localhost:4000 🚀🚀`);
});