Created
December 3, 2019 16:52
-
-
Save rriamarria/5be8010b929dd857e5a3c2643c21ef39 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 mysql = require('mysql'); | |
const connection = mysql.createConnection({ | |
host: 'localhost', | |
user: 'root', | |
password: process.env['SQLPASSWORD'], | |
database: 'my_db', | |
}) | |
module.exports = connection; |
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 connection = require('./conf'); | |
app.get('/api/movies', (req, res) => { | |
connection.query('SELECT * from movie', (err, results) => { | |
if (err) { | |
res.status(500).send(`Error retrieving the movies: ${err}`); | |
} 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 retrieving movie names: ${err}`); | |
} else { | |
res.json(results); | |
} | |
}) | |
}); | |
app.listen(3000, (err) => { | |
if(err) { | |
throw new Error('Something bad happened...') | |
} | |
console.log(`Server is listening on ${3000}`) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment