-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (29 loc) · 804 Bytes
/
index.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
require('dotenv').config();
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
const mysql = require('mysql');
const connection = mysql.createConnection({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME
});
connection.connect((err) => {
if (err) {
console.error('Error connecting to database: ', err);
return;
}
console.log('Connected to database');
});
app.get('/', (req, res) => {
connection.query('SELECT * FROM formulario', (err, rows) => {
if (err) throw err;
console.log('Data received from Db:\n');
console.log(rows);
res.send(rows);
});
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});