TypeScript NPM Module Boilerplate
Did you like the project? Please consider a donation to help improve!
TypeScript NPM Module Boilerplate ✨
- Overview
- Features
- Prerequisites
- Quick Start
- Usage
- Scripts
- Project Structure
- CI/CD
- Publishing
- Contributing
- License
Starter template for building and publishing typed Node.js libraries to npm using TypeScript, Jest, ESLint, and Prettier. It ships with sensible defaults, CI workflows, coverage upload to Codecov, and a minimal example implementation.
- TypeScript build with declaration output to
lib/
. - Jest test setup with
ts-jest
and coverage. - ESLint + Prettier configured for TS.
- GitHub Actions for tests/coverage and npm publish on release.
- Prepublish hooks to lint and test before publishing.
- Node.js 18+ (LTS recommended).
- npm 9+.
Option A — Use as template (recommended):
- Click “Use this template” on GitHub to create your repo.
- Clone your new repo and install dependencies:
git clone https://github.com/<your-username>/<your-repo>.git
cd <your-repo>
npm install
Option B — Clone this repository directly:
git clone https://github.com/hebertcisco/ts-npm-package-boilerplate
cd ts-npm-package-boilerplate
npm install
# Optional: reset git history
rm -rf .git && git init && git add . && git commit -m "Initial commit"
Then update package.json
fields: name
, version
, description
, author
, repository
, bugs
, and homepage
.
Edit the icon on Figma if you want:

This template includes a simple Uuid
helper as an example. After building, the entry point is lib/index.js
with types in lib/index.d.ts
.
Example:
import uuid from 'ts-npm-package-boilerplate';
// or: import { Uuid } from 'ts-npm-package-boilerplate';
const id = uuid.v4();
console.log(id); // 3f52c6f8-7a8e-4c04-b4a0-bf5f7d3e9f0a
During development (from this repo):
import uuid from './src';
npm run build
: Compile TypeScript tolib/
.npm test
: Run tests with Jest.npm run lint
: Lint code with ESLint.npm run lint:fix
: Fix lint issues.npm run format
: Format with Prettier.
Important lifecycle hooks:
prepare
: Runsnpm run build
so the package is built before pack/publish.prepublishOnly
: Runs tests and linting beforenpm publish
.version
: Formats and stages changes when bumping version withnpm version
.
src/
: Source code (TypeScript).src/helpers/uuid.ts
: Example implementation.src/__tests__/
: Jest tests.lib/
: Compiled JS + type definitions (generated).
GitHub Actions are included:
.github/workflows/coverage.yml
: Runs tests on Node 18/20/22 and uploads coverage to Codecov. SetCODECOV_TOKEN
secret for private repos..github/workflows/npm-publish.yml
: On GitHub release creation, builds and publishes to npm. SetNPM_TOKEN
secret with publish rights.
- Ensure you are logged in:
npm login
. - Update
package.json
metadata and ensurefiles
includes what you want to publish. - Bump version:
npm version patch|minor|major
. - Publish:
npm publish
.
Alternatively, create a GitHub Release and let the publish workflow handle it (requires NPM_TOKEN
).
Contributions, issues, and feature requests are welcome. Check the issues page: https://github.com/hebertcisco/ts-npm-package-boilerplate/issues
Give a ⭐️ if this project helps you!
Or buy me a coffee 🙌🏾
Copyright © 2025 @hebertcisco.
This project is MIT licensed.