DB.js
604 Bytes
const express = require("express");
const mysql = require("mysql");
const fs = require("fs");
const router = express.Router();
const [id, pw] = fs
.readFileSync("server/libs/sql.pvdata", "utf8")
.split("\r\n");
const connection = mysql.createConnection({
host: "localhost",
user: id,
password: pw,
database: "mydb",
});
router.get("/", (req, res) => {
res.send("DB Root");
});
router.get("/mytable", (req, res) => {
connection.query("SELECT * from mytable", (error, rows) => {
if (error) throw error;
console.log(rows);
res.send(rows);
});
});
module.exports = router;