Skip to main content

Posts

Showing posts with the label Open Source

How to Build and Publish a Custom Node.js Utility Package

Build a Custom Node.js Utility Package – Step-by-Step Guide 🚀 View GitHub Repo: node-custom-package-guide 💡 Want to reuse common string operations like capitalize() or slugify() across projects? Learn how to create and publish your own Node.js utility package! 📁 Project Structure custom-package/ ├── index.js ├── package.json ├── README.md └── utils/ ├── capitalize.js ├── camelCase.js ├── slugify.js └── greeting.js ✅ Initialize the Package npm init -y This creates a package.json with default values. 🧩 Write Utility Functions utils/capitalize.js function capitalize(str) { return str.charAt(0).toUpperCase() + str.slice(1); } module.exports = capitalize; utils/camelCase.js function camelCase(str) { return str .replace(/\s(.)/g, (match, group1) => group1.toUpperCase()) .replace(/\s/g, '') .replace(/^(.)/, (match, group1) => group1.toLowerCase()); } module.exports ...