Course contentsShow
← JavaScript
Lesson 2543 of 2,72351. Package ManagementFree lesson

Files, Bin, and Man

Controlling which files are published, exposing CLI executables, and providing man pages.

Files, Bin, and Man

You'll learn how to control package publication, expose command-line tools, and provide documentation through specific package.json fields.

The "files" Field

When you publish a package to NPM, you probably don't want to include everything—no tests, no build configs, no .git folder. The files field is your whitelist of what gets included:

{
  "files": [
    "dist/",
    "lib/",
    "README.md"
  ]
}

Think of it like packing a suitcase: you explicitly choose what goes in. Without this field, NPM uses defaults (including package.json, README, and your main entry), but you gain precise control by specifying it. Note: .npmignore can also exclude files, but files is clearer and more explicit.

The "bin" Field

Want your package to provide a command-line tool? The bin field maps command names to executable scripts:

{
  "name": "my-cli-tool",
  "bin": {
    "my-tool": "./bin/cli.js"
  }
}

When users install your package globally or via npx, NPM creates a symlink so typing my-tool runs your script. Your script needs a shebang (#!/usr/bin/env node) at the top. For a single command matching your package name, you can use shorthand: "bin": "./bin/cli.js".

The "man" Field

For Unix-style manual pages, the man field points to documentation files:

{
  "man": "./man/my-tool.1"
}

Users can then run man my-tool to read your docs. Multiple man pages go in an array.

Key Takeaway: Use files to control what's published, bin to expose CLI commands, and man to provide traditional Unix documentation—three fields that shape how users consume your package.