Created
December 6, 2019 10:07
-
-
Save rriamarria/11153670c522b1a850b757c6f9260e31 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'); | |
const bodyParser = require('body-parser'); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({ | |
extended: true | |
})); | |
app.post('/api/movie', (req, res) => { | |
const formData = req.body; | |
connection.query('INSERT INTO movie SET ?', formData, (err, results) => { | |
if (err) { | |
console.log(err); | |
res.status(500).send("Error saving an employee"); | |
} else { | |
res.status(200).send(formData); | |
} | |
} | |
); | |
} | |
); | |
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