45 lines
893 B
JavaScript
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');
|
|
});
|