-
Notifications
You must be signed in to change notification settings - Fork 205
/
app.js
38 lines (31 loc) · 881 Bytes
/
app.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
const express = require('express')
const mysql = require('mysql');
const app = express()
const path = require('path')
require('dotenv').config();
// Import Middleware
const logger = require('./middleware/logger')
app.use(logger)
const connection = require('./middleware/db_connect');
// Dashboard
app.use('/', express.static(path.join(__dirname, 'public')));
app.get('/app1', (req, res) => {
res.send('Hello this Apps 1!')
});
app.get('/app2', (req, res) => {
res.send('Hello this App 2!')
});
app.get('/users', (req, res, next) => {
const sql = "SELECT * FROM tb_data ORDER BY id desc"
connection.query(sql,(error, fields) => {
if (error) {
console.log('error', error)
} else {
res.send(fields)
}
})
});
app.listen(process.env.APP_PORT, () => {
console.log(`Example app listening on port ${process.env.APP_PORT}`)
})
module.exports = app