🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

testcontainers

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
t

testcontainers

Testcontainers is a NodeJS library that supports tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container

10.25.0
latest
96

Supply Chain Security

100

Vulnerability

81

Quality

92

Maintenance

100

License

Network access

Supply chain risk

This module accesses the network.

Found 1 instance in 1 package

Shell access

Supply chain risk

This module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.

Found 1 instance in 1 package

Dependencies have 3 high alerts.

Socket optimized override available

Version published
Weekly downloads
782K
16.69%
Maintainers
1
Weekly downloads
 
Created
Issues
28

What is testcontainers?

The testcontainers npm package is a library that provides lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container. It is primarily used for integration testing, allowing developers to run tests against real instances of services without the overhead of managing those services manually.

What are testcontainers's main functionalities?

Running a PostgreSQL container

This feature allows you to run a PostgreSQL container for testing purposes. The code sample demonstrates how to start a PostgreSQL container with a specified password and expose the default port.

const { GenericContainer } = require('testcontainers');
(async () => {
  const container = await new GenericContainer('postgres')
    .withEnv('POSTGRES_PASSWORD', 'password')
    .withExposedPorts(5432)
    .start();
  console.log(`PostgreSQL started on port ${container.getMappedPort(5432)}`);
})();

Running a Redis container

This feature allows you to run a Redis container for testing purposes. The code sample demonstrates how to start a Redis container and expose the default port.

const { GenericContainer } = require('testcontainers');
(async () => {
  const container = await new GenericContainer('redis')
    .withExposedPorts(6379)
    .start();
  console.log(`Redis started on port ${container.getMappedPort(6379)}`);
})();

Running a custom Docker container

This feature allows you to run any custom Docker container for testing purposes. The code sample demonstrates how to start a custom Docker container and expose a specified port.

const { GenericContainer } = require('testcontainers');
(async () => {
  const container = await new GenericContainer('your-custom-image')
    .withExposedPorts(8080)
    .start();
  console.log(`Custom container started on port ${container.getMappedPort(8080)}`);
})();

Other packages similar to testcontainers

FAQs

Package last updated on 01 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts