-
Notifications
You must be signed in to change notification settings - Fork 0
/
myapp.js
45 lines (34 loc) · 1.13 KB
/
myapp.js
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
34
35
36
37
38
39
40
41
42
43
44
45
const express = require('express');
const cors = require('cors');
const sequelize = require('./config/database');
require('dotenv').config();
const app = express();
const PORT = process.env.PORT || 3000;
// Middleware
app.use(cors());
app.use(express.json());
// Rutas
app.use('/scrape', require('./routes/scrapper'));
sequelize
.authenticate()
.then(() => console.log('Conexión exitosa con la base de datos.'))
.catch((error) => console.error('Error al conectar con la base de datos:', error));
// Sincronización de modelos
sequelize.sync({ force: false })
.then(() => console.log('Tablas sincronizadas.'))
.catch((error) => console.error('Error al sincronizar las tablas:', error));
async function listTables() {
try {
const tables = await sequelize.query("SHOW TABLES", { type: sequelize.QueryTypes.SHOWTABLES });
console.log('Tablas:', tables);
} catch (error) {
console.error('Error listing tables:', error);
}
}
listTables();
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});
app.get('/', (req, res) => {
res.send('Server is running! Use /scrape for scraping.');
});