This question has already been answered:
There is a function. The node.js server should return the result of the sql query, but because of the asynchronous nature of js, I can't get the result back because the base doesn't have time to work. Before that, I worked with synchronous languages.
function getCollections() { res = 0; var conn = new sql.Connection(dbConfig); conn.connect().then(function (recordset) { var req = new sql.Request(conn); req.query("SELECT * FROM Collections").then(function (recordset) { conn.close(); res = recordset; }) .catch(function (err) { console.log(err); conn.close(); }) }) .catch(function (err) { console.log(err); }); while (res === 0) { console.log(1);} } app.get("/", function (request, response) { var res = getCollections(); response.send(res); });