Skip to content

Instantly share code, notes, and snippets.

@dragonslayer77
Created May 22, 2019 10:36
Show Gist options
  • Save dragonslayer77/1a5db8ce9e08c92c817e20b232c03f22 to your computer and use it in GitHub Desktop.
Save dragonslayer77/1a5db8ce9e08c92c817e20b232c03f22 to your computer and use it in GitHub Desktop.
const express = require('express');
const app = express();
const port = 3000;
const connection = require('./db');
app.get('/api/movies', (request, response) => {
connection.query('SELECT * FROM movie', (error, result) => {
if (error) {
throw error;
}
response.send(result);
});
});
app.get('/api/movies/names', (request, response) => {
connection.query('SELECT name FROM movie', (error, result) => {
if (error) {
throw error;
}
response.send(result);
});
});
app.listen(port, (err) => {
if (err) {
throw new Error('Something bad happened...');
}
console.log(`Server is listening on ${port}`);
});
^^index.js file
(more info in database.js file like connection to mysql and passwords)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment