postgres-node-container
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Postgres node container

Setup a postgres container from NodeJS. Ideal for testing or a throwaway database.

Installation

npm install --save postgres-node-container

Usage

Example usage of setting up a postgres container from NodeJS

import {PostgresNodeContainerService} from "postgres-node-container";

// setup a postgres container with random port and default credentials
const postgresContainerService = new PostgresNodeContainerService();
const postgresContainer = await postgresContainerService.setupPostgresContainer();

// pass options to create a postgres client. Or pass the connection options to your ORM this is just a example usage
const client = new Client({
    user: postgresContainer.postgresUsername,
    host: postgresContainer.postgresHost,
    database: postgresContainer.postgresDatabase,
    password: postgresContainer.postgresPassword,
    port: postgresContainer.postgresPort,
});


// Will stop the container and delete the database content
await postgresContainer.stop();

Or set custom database with custom settings and credentials

const username = 'johnDoe';
const password = 'superSecret';
const database = 'superSecret';
const databaseVersion = '11-alpine';

const postgresContainerService = new PostgresNodeContainerService();
const postgresContainer = await postgresContainerService.setupPostgresContainer(username, password, database, databaseVersion);
const client = new Client({
    user: postgresContainer.postgresUsername,
    host: postgresContainer.postgresHost,
    database: postgresContainer.postgresDatabase,
    password: postgresContainer.postgresPassword,
    port: postgresContainer.postgresPort,
});

await postgresContainer.stop();

You can also get generate connection string from the container

const postgresContainerService = new PostgresNodeContainerService();
const postgresContainer = await postgresContainerService.setupPostgresContainer();
const connectionString = postgresContainer.getPostgresConnectionString();

// connection string for example postgres://postgres:postgres@localhost:32768/postgres

Development

Install dependencies

npm install

Run tests

npm run test

Project roadmap

  • [x] Start postgres container
  • [x] Stop container
  • [x] Get connection details
  • [x] Select postgres version
  • [x] Add tests
  • [x] Add examples
  • [x] Add documentation
  • [ ] Fix package installation and usage with examples

/postgres-node-container/

    Package Sidebar

    Install

    npm i postgres-node-container

    Weekly Downloads

    1

    Version

    1.0.2

    License

    ISC

    Unpacked Size

    18.5 kB

    Total Files

    17

    Last publish

    Collaborators

    • lukasberk