How can I retrieve the parameter "results" outside of the function
The result return a json format
Indeed, let users worked but I want use the same thing but now, with the array of results inside the function
Thanks for your help :)
// connect to database
dbConn.connect();
router.use(passport.initialize());
router.use(passport.session());
// Retrieve all users
router.get('/api/users', (req, res) => {
dbConn.query('SELECT * FROM users', function (error, results, fields) {
if (error) throw error;
return res.json({ data: results });
});
});
Value of results
:
[
{
"id": 1,
"name": "admin",
"email": "admin@gmail.com",
"password": "admin"
},
{
"id": 2,
"name": "emma",
"email": "emma@gmail.com",
"password": "password2"
}
]