Skip to content

Instantly share code, notes, and snippets.

@rriamarria
Created December 6, 2019 10:07
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/11153670c522b1a850b757c6f9260e31 to your computer and use it in GitHub Desktop.
Save rriamarria/11153670c522b1a850b757c6f9260e31 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');
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