# Node

Represents the construct node in the scope tree.

- Source: [`src/construct.ts`](https://github.com/aws/constructs/blob/v10.8.1/src/construct.ts#L34)

## Example

```ts
import { Node } from 'constructs';

const node = new Node(host, scope, id);
```

## Initializer

```ts
new Node(host: Construct, scope: IConstruct, id: string)
```

## Properties

- `addr`: string — An opaque, deterministic address for this construct, derived from its path.

  The address is a 42 character string: the prefix "c8" followed by 40
  lowercase hexadecimal characters (0-9a-f). It is a SHA-1 over the ids of
  the constructs on the path from the root of the tree down to this
  construct.

  To enable refactoring of construct trees, constructs with the ID `Default`
  are excluded from the calculation. Within a tree, `a/Default/b` and `a/b`
  have the same address.

  This means the address is *not* guaranteed to identify a construct uniquely:

  - Any construct whose path is made up of the same ids has the same address.
    Two trees that are shaped alike therefore hand out the same addresses.
  - As described above, a construct under a `Default` scope has the same
    address as its counterpart outside of that scope.
  - The digest is of fixed width, so even distinct paths can in principle hash
    to the same address. SHA-1 in particular is no longer collision resistant.

  Use an address to derive stable, deterministic names from the location of a
  construct in the tree. Do not use it as the identity of a construct:
  instead, compare construct instances or use the `path`.

  ```ts
  c83a2846e506bcc5f10682b564084bca2d275709ee
  ```

- `children`: [IConstruct](/cdk/api/v2/docs/constructs.IConstruct.html)[] — All direct children of this construct.

- `defaultChild`: [IConstruct](/cdk/api/v2/docs/constructs.IConstruct.html) — Returns the child construct that has the id `Default` or `Resource`.

  This is usually the construct that provides the bulk of the underlying functionality.
  Useful for modifications of the underlying construct that are not available at the higher levels.
  Override the defaultChild property.

  This should only be used in the cases where the correct
  default child is not named 'Resource' or 'Default' as it
  should be.

  If you set this to undefined, the default behavior of finding
  the child named 'Resource' or 'Default' will be used.

- `dependencies`: [IConstruct](/cdk/api/v2/docs/constructs.IConstruct.html)[] — Constructs that this construct depends on directly.

  This expands the sets of `Dependables` to the set of `Constructs` that they
  represent.

- `id`: string — The id of this construct within the current scope.

  This is a scope-unique id. To obtain an id that reflects the full location
  of this construct in the tree, use `path` or `addr`.

- `locked`: boolean — Returns true if this construct or the scopes in which it is defined are locked.

- `metadata`: [MetadataEntry](/cdk/api/v2/docs/constructs.MetadataEntry.html)[] — An immutable array of metadata objects associated with this construct.

  This can be used, for example, to implement support for deprecation notices, source mapping, etc.

- `path`: string — The full, absolute path of this construct in the tree.

  Components are separated by '/'.

- `PATH_SEP`: string (static) — Separator used to delimit construct path components.

- `root`: [IConstruct](/cdk/api/v2/docs/constructs.IConstruct.html) — Returns the root of the construct tree.

- `scope`: [IConstruct](/cdk/api/v2/docs/constructs.IConstruct.html) — Returns the scope in which this construct is defined.

  The value is `undefined` at the root of the construct scope tree.

- `scopes`: [IConstruct](/cdk/api/v2/docs/constructs.IConstruct.html)[] — All parent scopes of this construct.

## Methods

- `addDependency(...deps: IDependable[]): void` — Add an ordering dependency on a Dependable (a construct or set of constructs).

  It is up to the target document language to decide what an ordering
  relationship means and how it should be rendered; for example, in the AWS
  CDK for CloudFormation it means a dependency from every resource in scope
  of the current construct to every resource in scope of the target set
  of constructs, that get realized as either stack dependencies or
  `DependsOn` relationships in the synthesized template.

  `IDependable` is a marker interface that indicates that a class has used
  `Dependable.implement()` to implement the `IDependable` interface. It
  can be used to make the target object represent more than one set of
  constructs at a time. For example, a `DependencyGroup` uses this
  interface to represent an explicit list of 0 or more constructs that should
  be involved in the dependency relationship.

- `addMetadata(type: string, data: any, options?: MetadataOptions): void` — Adds a metadata entry to this construct.

  Entries are arbitrary values and will also include a stack trace to allow tracing back to
  the code location for when the entry was added. It can be used, for example, to include source
  mapping in CloudFormation templates to improve diagnostics.
  Note that construct metadata is not the same as CloudFormation resource metadata and is never written to the CloudFormation template.
  The metadata entries are written to the Cloud Assembly Manifest if the `treeMetadata` property is specified in the props of the App that contains this Construct.

  **Parameters**

  - `type` — a string denoting the type of metadata.
  - `data` — the value of the metadata (can be a Token).
  - `options` — options.

- `addValidation(validation: IValidation): void` — Adds a validation to this construct.

  When `node.validate()` is called, the `validate()` method will be called on
  all validations and all errors will be returned.

  **Parameters**

  - `validation` — The validation object.

- `findAll(order?: ConstructOrder): IConstruct[]` — Return this construct and all of its children in the given order.

- `findChild(id: string): IConstruct` — Return a direct child by id.

  Throws an error if the child is not found.

  **Parameters**

  - `id` — Identifier of direct child.

  **Returns:** Child with the given id.

- `getAllContext(defaults?: json): any` — Retrieves the all context of a node from tree context.

  Context is usually initialized at the root, but can be overridden at any point in the tree.

  **Parameters**

  - `defaults` — Any keys to override the retrieved context.

  **Returns:** The context object or an empty object if there is discovered context

- `getContext(key: string): any` — Retrieves a value from tree context if present. Otherwise, would throw an error.

  Context is usually initialized at the root, but can be overridden at any point in the tree.

  **Parameters**

  - `key` — The context key.

  **Returns:** The context value or throws error if there is no context value for this key

- `lock(): void` — Locks this construct from allowing more children to be added.

  After this
  call, no more children can be added to this construct or to any children.

- `of(construct: IConstruct): Node // chainable` (static) — use `construct.node` instead

  **Parameters**

  - `construct` — the construct.

- `removeDependency(...deps: IDependable[]): void` — Remove an ordering dependency on a Dependenable (a construct or set of constructs).

  This removes any dependency added using `node.addDependency()`. It must
  use the exact same object that was involved in the `addDependency()` call.

- `setContext(key: string, value: any): void` — This can be used to set contextual values.

  Context must be set before any children are added, since children may consult context info during construction.
  If the key already exists, it will be overridden.

  **Parameters**

  - `key` — The context key.
  - `value` — The context value.

- `tryFindChild(id: string): IConstruct` — Return a direct child by id, or undefined.

  **Parameters**

  - `id` — Identifier of direct child.

  **Returns:** the child if found, or undefined

- `tryGetContext(key: string): any` — Retrieves a value from tree context.

  Context is usually initialized at the root, but can be overridden at any point in the tree.

  **Parameters**

  - `key` — The context key.

  **Returns:** The context value or `undefined` if there is no context value for this key.

- `tryRemoveChild(childName: string): boolean` — Remove the child with the given name, if present.

  **Returns:** Whether a child with the given name was deleted.

- `validate(): string[]` — Validates this construct.

  Invokes the `validate()` method on all validations added through
  `addValidation()`.

  **Returns:** an array of validation error messages associated with this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.

  **Parameters**

  - `mixins` — The mixins to apply.

  **Returns:** This construct for chaining
