# containsPackageJson

**Kind:** Function

**Source:** [`tools/gulp/util/task-helpers.ts`](https://github.com/nestjs/nest/blob/master/tools/gulp/util/task-helpers.ts#L21)

Checks if the directory contains a package.json file

`containsPackageJson` checks whether a specified directory contains a `package.json` file. It is used by Gulp task helpers to identify Node.js package directories before applying package-specific build, packaging, or dependency-processing logic.

## Signature

```ts
function containsPackageJson(dir: string)
```

## Parameters

| Name | Type |
|---|---|
| `dir` | `string` |

## Diagram

```mermaid
graph LR
  A[Directory path] --> B[containsPackageJson]
  B --> C{package.json exists?}
  C -->|Yes| D[Return true]
  C -->|No| E[Return false]
```

## Usage

```ts
import { containsPackageJson } from './tools/gulp/util/task-helpers';

const packageDirectory = './extensions/my-extension';

if (containsPackageJson(packageDirectory)) {
	console.log('This directory is a Node.js package.');
} else {
	console.log('No package.json found.');
}
```

## AI Coding Instructions

- Pass a directory path, not a path to `package.json` itself; the helper performs the filename check internally.
- Use this helper before running package-specific Gulp tasks or reading package metadata.
- Treat a `false` result as an expected condition for non-package directories rather than an error.
- Keep filesystem existence checks centralized through this utility when working in Gulp task helpers.
