Skip to content

Instantly share code, notes, and snippets.

@hieptl
Created November 16, 2021 02:09
Show Gist options
  • Save hieptl/b8629bd1948c1bc8da67c436c35af0f0 to your computer and use it in GitHub Desktop.
Save hieptl/b8629bd1948c1bc8da67c436c35af0f0 to your computer and use it in GitHub Desktop.
users.js - routes - server - load user by id - Instagram Clone React Node
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