Files
sql/server/index.js
2025-02-02 15:40:23 +09:00

45 lines
893 B
JavaScript

require('dotenv').config()
const express = require('express')
const sequelize = require('./db')
const PORT = process.env.PORT || 5000
const app = express()
process.on('uncaughtException', function (err) {
console.log(err);
});
/* const nachalo = async () => {
try {
await sequelize.authenticate()
await sequelize.sync()
app.listen(PORT, () => console.log(`Server started on port http://localhost:${PORT}`))
} catch(errors) {
console.log(errors)
}
}
nachalo() */
app.get('/api/data', (req, res) => {
db.query('SELECT * FROM your_table', (error, results) => {
if (error) throw error;
res.json(results);
});
});
app.listen(PORT, () => {
console.log(`Сервер запущен на порту http://localhost:${PORT}`);
});
app.get('/', (req, res) => {
res.send('Welcome to the homepage');
});