Created
November 8, 2021 14:28
-
-
Save vmalep/941173acd3c708caa6184e3872770f91 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
app.post('/api/users', (req, res) => { | |
const { firstname, lastname, email } = req.body | |
connection.promise().query( | |
'INSERT INTO users(firstname, lastname, email) VALUES (?, ?, ?)', | |
[firstname, lastname, email],) | |
.then(result=>res.status(201).send('User successfully saved') | |
.catch(err=>res.status(500).send('Error saving the user')) | |
) | |
}) | |
// If needed to check the result | |
app.get('/api/users', (req, res) => { | |
connection.promise().query('SELECT * FROM users') | |
.then(result=>res.status(200).json(result)) | |
.catch(err=>res.status(500).send('Error retrieving data from database')) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment