# npm-init-template

> Create 'npm init' packages easily with templates and prompts

Latest version **4.3.3** (published 2026-05-01) · BlueOak-1.0.0 license · 0 weekly downloads

## Install

```sh
npm install npm-init-template
pnpm add npm-init-template
yarn add npm-init-template
bun add npm-init-template
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.3.3 |
| Published | 2026-05-01 |
| First published | 2023-05-24 |
| Weekly downloads | 0 |
| License | BlueOak-1.0.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | 20 \|\| >=22 |
| Dependencies | 5 |
| Unpacked size | 57.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2425 |
| Author | Isaac Z. Schlueter |
| Maintainers | isaacs |

## Links

- npm: https://www.npmjs.com/package/npm-init-template
- Repository: https://github.com/tapjs/tapjs
- Homepage: https://github.com/tapjs/tapjs/tree/main/src/npm-init-template#readme
- Issues: https://github.com/tapjs/tapjs/issues
- Funding: https://github.com/sponsors/isaacs
- npm.io page: https://npm.io/package/npm-init-template

## Dependencies (5)

- [read](https://npm.io/package/read.md) ^4.1.0
- [mkdirp](https://npm.io/package/mkdirp.md) ^3.0.1
- [mustache](https://npm.io/package/mustache.md) ^4.2.0
- [minimatch](https://npm.io/package/minimatch.md) ^10.0.1
- [foreground-child](https://npm.io/package/foreground-child.md) ^4.0.0

## Recent versions

- 4.3.3 (latest) — 2026-05-01
- 1.0.3 (pre) — 2023-09-15
- 4.3.2 — 2026-04-05
- 4.3.1 — 2026-02-05
- 4.3.0 — 2025-12-01
- 4.2.0 — 2025-11-25
- 4.1.0 — 2025-11-25
- 4.0.3 — 2025-11-23
- 4.0.2 — 2025-11-01
- 4.0.1 — 2025-10-02
- 4.0.0 — 2024-07-08
- 3.0.0 — 2024-06-24
- 2.0.1 — 2024-05-24
- 2.0.0 — 2024-05-21
- 1.1.1 — 2023-10-31
- … 7 more at https://npm.io/package/npm-init-template/versions

## README

# npm-init-template

This is a library for building `npm init` packages more easily,
by providing a set of utility functions for collecting
information and then creating the starter package from a folder
of template files.

## USAGE

Create a package that exports a single `bin` command:

```json
{
  "name": "create-my-special-thing",
  "version": "1.0.0",
  "description": "npm init my-special-thing",
  "bin": "index.mjs"
}
```

Then in that bin script (shown here as `index.mjs`), put code
like this:

```js
#!/usr/bin/env node
import { Init } from 'npm-init-template'

// Provide it with the path to this file, so we know how to find
// the template files.  If using commonjs, use __filename instead.
const { prompt, build, values, positionals, run } = new Init(
  import.meta.url,
)

// any prompts that the user already set in the command line,
// like with --foo=bar will be automatically set in the values
// already, and will skip the prompt
// Otherwise, these will update the values object appropriately.
await prompt('What is your name?', 'name')
await prompt('What is your quest?', 'quest')
// third arg is passed as options to `read`
await prompt('What is your favorite color?', 'color', {
  default: 'blue',
})
await prompt(
  'What is the flight average velocity of an unladen sparrow?',
  'sparrow',
)

if (values.sparrow === "I don't know") {
  throw new Error('AAAHHHH!!!!')
}

await build({
  // The folder where the templates live
  // Any files that named *.mustache will be expanded using
  // the values object built up by the prompts.
  // Any other kinds of files will be copied as-is.
  //
  // Default is './templates'

  // templates: './templates',

  // Set the settings for template file handling.
  //
  // By default:
  //
  // Any file named *.{json,js,ts,jsx,tsx}.mustache will use the
  // template tags <% %> instead of {{ }}, and JSON.stringify
  // escaping instead of HTML escaping.
  //
  // Any file named *.{html,xhtml,xml}.mustache will be escaped using
  // HTML escaping by default.
  //
  // Any other kind of *.mustache file will not escape values
  // (default behavior can be overridden by setting the '*'
  // member here)
  //
  // add/adjust as you see fit

  // templateSettings: {
  //   bash: {
  //     tags: ['(%', '%)'],
  //     escape: text => JSON.stringify(text),
  //   }
  // },

  // of course, you can also change the mustache tags in the
  // template itself, using the syntax like `{{=(% %)=}}`

  // the folder to build the package in. To build in place,
  // use `target: '.'`
  // this is required.
  // positionals is the positional arguments read by parseArgs
  target: positionals[0] || `${values.name}-${values.quest}`,

  // glob pattern(s) of template files to include, defaults to '**'
  // You can use this for example to conditionally only include
  // tsconfig and .ts files if the user has opted into typescript
  // This is matched against the file being written, so without
  // the '.mustache' extension.
  // include: '**',
  // include: ['tsconfig*.json', 'src/**/*.ts'],

  // excludes take priority over includes. This will omit
  // templates from the built results. Defaults to undefined (ie,
  // include everything.)
  // exclude: 'files/to/exclude/**',
})

// after building, you can run stuff in the folder, if you want
await run('npm install')
```

In `./templates/quest.html.mustache`, you can put [mustache
templates](https://github.com/janl/mustache.js/), something like
this:

```html
<html>
  <body style="background-color:{{ color }}">
    <h1>Hello, {{name}}!</h1>
    <p>Good luck on {{quest}}.</p>
    <p>
      The average flight velocity of an unladen sparrow is {{ sparrow }}.
    </p>
  </body>
</html>
```

JSON files use `JSON.stringify` as the default escaping
mechanism, so in `templates/package.json.mustache`, you can put
something like this:

```json
{
  "name": <% name %>,
  "description": <% quest %>
}
```

Templates can also include each other as partials, each will be
loaded with its name relative to the templates folder.

```html
<html>
  <body style="background-color:{{ color }}">
    <h1>Hello, {{name}}!</h1>
    <p>Good luck on {{quest}}.</p>
    <p>
      The average flight velocity of an unladen sparrow is {{ sparrow }}.
    </p>

    <p>Your `package.json` file is:</p>
    <pre>{{>package.json}}</pre>
  </body>
</html>
```

---
_Source: https://npm.io/package/npm-init-template · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
