Created
November 16, 2021 02:09
-
-
Save hieptl/b8629bd1948c1bc8da67c436c35af0f0 to your computer and use it in GitHub Desktop.
users.js - routes - server - load user by id - Instagram Clone React Node
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.get('/users/:id', (req, res) => { | |
const userId = req.params.id; | |
if (!userId) { | |
res.status(200).jsonp({ message: 'Cannot load user information, please try again' }); | |
} | |
const getUserSql = "SELECT * FROM user_account WHERE id = ?"; | |
dbConn.query(getUserSql, [userId], function (error, response) { | |
if (response && response.length) { | |
res.status(200).jsonp(response); | |
} else { | |
res.status(200).jsonp({ message: 'Cannot load user information, please try again' }); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment