Languages
[Edit]
EN

Node.js - PostgreSQL Drop database

0 points
Created by:
Dirask Admin - MR
1340

In this article, we would like to show you how to drop a Postgres database in Node.js.

const { Client } = require('pg');

const client = new Client({
    host: '127.0.0.1',
    user: 'postgres',
    database: 'database_name',
    password: 'password',
    port: 5432,
});

const execute = async (query) => {
    try {
        await client.connect();     // gets connection
        await client.query(query);  // sends queries
        return true;
    } catch (error) {
        console.error(error.stack);
        return false;
    } finally {
        await client.end();         // closes connection
    }
};

execute('DROP DATABASE example_db').then(result => {
    if (result) {
        console.log('Database removed');
    }
});

Node.js - PostgreSQL

Native Advertising
­čÜÇ
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé

Join