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);
        });
}

1 Answer 1

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:[email protected]:portnumber",
"https.proxy": "http://user:[email protected]: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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.