Skip to content

Instantly share code, notes, and snippets.

@justinehell
Last active September 13, 2020 14:38
Show Gist options
  • Save justinehell/7e46d18aa69ad7575b7cc252285cebed to your computer and use it in GitHub Desktop.
Save justinehell/7e46d18aa69ad7575b7cc252285cebed to your computer and use it in GitHub Desktop.
Express 2 - Express, MySQL, Postman
const express = require("express");
const app = express();
const port = 3000;
const connection = require("./conf");
app.get("/api/movies", (req, res) => {
connection.query("SELECT * from movie", (err, results) => {
if (err) {
res.status(500).send("Error while recovering movies");
} else {
res.json(results);
}
});
});
app.get("/api/movies/names", (req, res) => {
connection.query("SELECT name from movie", (err, results) => {
if (err) {
res.status(500).send("Error while recovering movies names");
} 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