Socket
Book a DemoInstallSign in
Socket

domain-parent

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

domain-parent

Adds a parent Node.js domain reference (parentDomain property) to all domains.

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

domain-parent 👪

Travis build status Coveralls NPM version Canonical Code Style Twitter Follow

Adds a parent Node.js domain reference (parentDomain property) to all domains.

Motivation

Domains provide a way to add context to a chain of asynchronous calls. Having a reference to the parentDomain allows to collect context from all parent domains.

Implementation

domain-parent monkey-patches Node.js domain create method. All domains that are created after Node.js has been shimmed will have parentDomain property. Top-level domain will have parentDomain set to NULL.

Usage

To shim Node.js, import domain-parent/auto, e.g.

import 'domain-parent/auto';
import domain from 'domain';

domain.parentDomain === null;

const d0 = domain.create();

d0.run(() => {
  process.domain.parentDomain === null;

  const d1 = domain.create();

  d1.run(() => {
    process.domain.parentDomain === d0;
  });
});

Do not use in distributed packages

Do not shim Node.js in distributable NPM package. If your package depends on parentDomain, then:

  • Check if Node.js is shimmed (require('domain').parentDomain !== undefined) and warn if Node.js is not shimmed.
  • Document that your package depends on parentDomain and provide instructions for adding domain-parent shim.

Keywords

domain

FAQs

Package last updated on 31 Jan 2020

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