简体   繁体   中英

Connection to postgresql from node js

I have created a user user_1 but how can I connect postgres user, not for user_1 ? I do not know port, password.

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

const pool = new Pool({
    user: 'user_1',
    host: 'localhost',
    database: 'info',
    password: '1234',
    port: 5432,
})

The default PostgreSQL port is 5432 . You can check your /etc/postgresql/9.6/main/postgresql.conf file under Connections and Authentication to find the port. (Replace 9.6 with your installation version)

If you didn't set up a password while creating a user, leave the password field blank. For a default installation and default user, the password might be postgres .

postgresql.conf

#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------

# - Connection Settings -

#listen_addresses = 'localhost'     # what IP address(es) to listen on;
                    # comma-separated list of addresses;
                    # defaults to 'localhost'; use '*' for all
                    # (change requires restart)
port = 5432             # (change requires restart)
max_connections = 100           # (change requires restart)
#superuser_reserved_connections = 3 # (change requires restart)
unix_socket_directories = '/var/run/postgresql' # comma-separated list of directories
                    # (change requires restart)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM