Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require("express");
- const mysql = require("mysql");
- // Creat the connection to the database
- const db = mysql.createConnection({
- host: "localhost",
- user: "root",
- password: "password",
- database: "tester"
- });
- // connect and error check
- db.connect(err => {
- if (err) {
- throw err;
- }
- console.log("MySQL connected properly");
- });
- // initiates an instance of express
- const app = express();
- app.get("/api/tester", (req, res) => {
- var items = [];
- var sql = "SELECT * FROM tester";
- var query = db.query(sql, function(err, rows) {
- if (err) throw err;
- res.json(rows);
- });
- });
- // TRYING TO FIGURE OUT THE DATABASE
- const port = 5000;
- app.listen(port, () => `Server running on port ${port}`);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement