Created
September 8, 2020 10:31
-
-
Save alyson-b69/98bff77095c24591d9a32e6bec7616dd to your computer and use it in GitHub Desktop.
Express 2 - EXPRESS MySQL POSTMAN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express"); | |
const app = express(); | |
const port = 3000; | |
const connection = require("./conf"); | |
app.get("/api/employees", (req, res) => { | |
connection.query("SELECT * from employee", (err, results) => { | |
if (err) { | |
res.status(500).send(err); | |
} else { | |
res.json(results); | |
} | |
}); | |
}); | |
app.get("/api/movies", (req, res) => { | |
connection.query("SELECT * from movie", (err, results) => { | |
if (err) { | |
res.status(500).send(err); | |
} else { | |
res.json(results); | |
} | |
}); | |
}); | |
app.get("/api/movies/name", (req, res) => { | |
connection.query("SELECT name from movie", (err, results) => { | |
if (err) { | |
res.status(500).send(err); | |
} else { | |
res.json(results); | |
} | |
}); | |
}); | |
app.listen(port, (err) => { | |
if (err) { | |
throw new Error("Something bad happened..."); | |
} | |
console.log(`Server is listening on ${port}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment