Skip to content

Instantly share code, notes, and snippets.

@rriamarria
Created December 3, 2019 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rriamarria/5be8010b929dd857e5a3c2643c21ef39 to your computer and use it in GitHub Desktop.
Save rriamarria/5be8010b929dd857e5a3c2643c21ef39 to your computer and use it in GitHub Desktop.
const mysql = require('mysql');
const connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: process.env['SQLPASSWORD'],
database: 'my_db',
})
module.exports = connection;
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