I'm new to javascript and nodejs and i have a question
I have a code who i'm working in a simple api and i'm getting a lot of trouble to understand why this is happening
app.get('/api/list_all', (req, res) => {
get_info(`SELECT * FROM users;`, function(result){
res.json(result);
});
});
I have this route to list all the users for me on screen for a local host mysql. The connection are working but when i type the route, returns me a blank screen with "[]" (empty list)
The console and the html page does not display any errors
But when i change the route for just "list_all" without the "api" part, it goes well. Like this:
app.get('/list_all', (req, res) => {
get_info(`SELECT * FROM users;`, function(result){
res.json(result);
});
});
It returns me with the SQL response.
The question is: why is not working when i give the "api" on route?
The function "get_info":
function get_info(sql_data, callback){
con.getConnection((error, conn) => {
if (error) { throw error; }
conn.query(
sql_data,
(error, resultado) => {
conn.release();
if (error) { throw error; }
return callback(resultado)
}
)
})
}
I was expecting the route "api/list_all" to return the SQL result with all users normally.