Created
May 22, 2019 10:36
-
-
Save dragonslayer77/1a5db8ce9e08c92c817e20b232c03f22 to your computer and use it in GitHub Desktop.
This file contains 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('./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