This repository serves as a starter template for developing and publishing an NPM library or package. It includes essential configurations, scripts, and best practices to streamline the development process.
- Pre-configured ESLint and Prettier for code consistency
- TypeScript support (optional, can be removed)
- Ready-to-use Jest setup for testing
- GitHub Actions for CI/CD
- Automated NPM publishing workflow
- Example usage and setup included
- Pre-configured package.json with necessary fields
Clone this repository and run:
git clone https://github.com/Eli-the-creator/npm-library-template.git
Modify the src/index.js
or src/index.ts
file with your custom package logic. Export your modules as needed.
Example:
// src/index.js
export function helloWorld() {
return "Hello, NPM!";
}
Then, import and use it in another project:
import { helloWorld } from 'your-package-name';
console.log(helloWorld()); // "Hello, NPM!"
Run the following commands:
npm run build
– Build the packagenpm test
– Run tests with Jestnpm publish
– Publish to NPM (ensure you're logged in)npm version patch
– Update version (useminor
ormajor
as needed)
- Ensure you have an NPM account (
npm login
). - Run
npm publish
to deploy your package.
For scoped packages (@username/package-name
), use:
npm publish --access public