Connect to the Database in Azure Functions (Javascript)

1

Alright?

I have faced a constant problem, and I do not know what to try to resolve it.

I created an Azure Function and need to query some data in the database, in order to return them as a function response.

I created a PostgreSQL Database on Azure, added the IP to the firewall, added the IP of my machine and created tables, and everything else.

However, when trying to connect to the database, within Azure Function, it simply does not return anything, nor does it connect.

What to do about it?

Thanks in advance!

My code:

module.exports = function (context, req) {
    const pg = require('pg');

    // Connect to DB with Long String in App Settings

    const client = new pg.Client(GetEnvironmentVariable("AzurePGDB"));
    client.connect();
    const query = 'select * from table';

    client.query(query, (err, res) => {
        context.res = {
           body: res
        }
    });

   context.done();
};

function GetEnvironmentVariable(name) {
    return name + ": " + process.env[name];
}
    
asked by anonymous 28.08.2018 / 21:34

0 answers