Common packages
Course: Actionable Docker - chapter 6
docker run -d -p 27017:27017 mongoPostgres
Section titled “Postgres”docker run -e POSTGRES_PASSWORD=mysecretpassword -d -p 5432:5432 postgresThe connection string for this postgres would be
postgresql://postgres:mysecretpassword@localhost:5432/postgresCode to test it out
// Import the pg libraryconst { Client } = require('pg');
// Define your connection string (replace placeholders with your actual data)const connectionString = 'postgresql://postgres:mysecretpassword@localhost:5432/postgres';
// Create a new client instance with the connection stringconst client = new Client({ connectionString: connectionString});
// Connect to the databaseclient.connect(err => { if (err) { console.error('connection error', err.stack); } else { console.log('connected to the database'); }});
// Run a simple query (Example: Fetching the current date and time from PostgreSQL)client.query('SELECT NOW()', (err, res) => { if (err) { console.error(err); } else { console.log(res.rows[0]); }
// Close the connection client.end();});