0

I use this script to connect node.js with Azure Postgresql. But the ssl verification of our firewall blocks the connection, so in the past I need to use a proxy. Where in the code can I add the proxy settings as like host and port? Means when I start the code, vscode should connect through the proxy to postgresql.

const pg = require('pg');

const config = {
    host: '<your-db-server-name>.postgres.database.azure.com',
    // Do not hard code your username and password.
    // Consider using Node environment variables.
    user: '<your-db-username>',     
    password: '<your-password>',
    database: '<name-of-database>',
    port: 5432,
    ssl: true
};

const client = new pg.Client(config);

client.connect(err => {
    if (err) throw err;
    else { queryDatabase(); }
});

function queryDatabase() {
  
    console.log(`Running query to PostgreSQL server: ${config.host}`);

    const query = 'SELECT * FROM inventory;';

    client.query(query)
        .then(res => {
            const rows = res.rows;

            rows.map(row => {
                console.log(`Read: ${JSON.stringify(row)}`);
            });

            process.exit();
        })
        .catch(err => {
            console.log(err);
        });
}
Eden1998
  • 119
  • 1
  • 11

1 Answers1

1

To configure proxy for Visual Studio Code

Edit the settings.json file

Depending on your platform, the user settings file is located here:

Windows: %APPDATA%\Code\User\settings.json

macOS: $HOME/Library/Application Support/Code/User/settings.json

Linux: $HOME/.config/Code/User/settings.json

Modify and Add the below lines to configure your proxy

"http.proxy": "http://user:pass@proxy.com:portnumber",
"https.proxy": "http://user:pass@proxy.com:portnumber",
"http.proxyStrictSSL": false

If your proxy doesn't require authentication, you could simply use

"http.proxy": "http://proxy.com:portnumber",
"https.proxy": "http://proxy.com:portnumber"
"http.proxyStrictSSL": false

Restart VS Code

The documentation related to settings and schema of the settings.json file is here for reference