@jnanda/a_library
v1.1.0
Published
my sample library
Readme
🚀 Captain.js — Complete npm Publishing Guide
This document contains everything needed to build, structure, and publish captain.js to npm professionally.
1️⃣ Prerequisites
Make sure you have:
- Node.js installed
- npm installed
- Git installed
- GitHub account
- npm account
Check versions:
node -v
npm -v
git --version2️⃣ Create Project Folder
mkdir captain-js
cd captain-js3️⃣ Create Library File
Create:
captain.jsAdd:
(function (global) {
const Captain = {
sum: function(a, b) {
return a + b;
},
multiply: function(a, b) {
return a * b;
},
capitalize: function(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
};
global.Captain = Captain;
})(typeof window !== "undefined" ? window : global);4️⃣ Initialize npm
npm init -yEdit package.json:
{
"name": "captain-js",
"version": "1.0.0",
"description": "A tiny OG JavaScript utility library",
"main": "captain.js",
"keywords": ["javascript", "utility", "library"],
"author": "Your Name",
"license": "MIT"
}⚠️ Note: Package name must be unique on npm.
5️⃣ Create README.md
Create:
README.mdExample content:
# Captain.js
A tiny OG JavaScript utility library.
## Installation
```bash
npm install captain-jsCDN Usage
<script src="https://cdn.jsdelivr.net/npm/[email protected]/captain.js"></script>Example
Captain.sum(2, 3); // 5
---
# 6️⃣ Create .gitignore
Create:
.gitignore
Add:
Dependencies
node_modules/
Logs
npm-debug.log* yarn-debug.log* yarn-error.log*
Environment files
.env .env.local
OS files
.DS_Store Thumbs.db
Optional future build folders
dist/ build/ coverage/
### Why `.gitignore`?
It prevents unnecessary files (like `node_modules`) from being committed to GitHub.
---
# 7️⃣ Create LICENSE (MIT)
Create:
LICENSE
Add:
MIT License
Copyright (c) 2026 Your Name
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software...
(Use full MIT template from https://opensource.org/licenses/MIT)
### Why License?
Without a license, legally no one can use your code.
MIT allows:
- Commercial use
- Modification
- Distribution
- Private use
Requires:
- Keeping copyright notice
---
# 8️⃣ Initialize Git
```bash
git init
git add .
git commit -m "Initial commit"9️⃣ Push to GitHub
Create a repository on GitHub named captain-js.
Then:
git remote add origin https://github.com/yourusername/captain-js.git
git branch -M main
git push -u origin main🔟 Login to npm
npm loginEnter username, password, email, and OTP if required.
Check login:
npm whoami1️⃣1️⃣ Publish to npm
npm publishIf successful:
+ [email protected]1️⃣2️⃣ CDN Usage (Automatic)
After publishing, your package is automatically available on CDN:
https://cdn.jsdelivr.net/npm/[email protected]/captain.jsUse in HTML:
<script src="https://cdn.jsdelivr.net/npm/[email protected]/captain.js"></script>1️⃣3️⃣ Updating Version
You cannot overwrite a published version.
Update version in package.json:
"version": "1.0.1"Then:
npm publish1️⃣4️⃣ Semantic Versioning
Format:
MAJOR.MINOR.PATCHExamples:
- 1.0.1 → Bug fix
- 1.1.0 → New feature
- 2.0.0 → Breaking change
📁 Final Folder Structure
captain-js/
│
├── captain.js
├── package.json
├── README.md
├── LICENSE
└── .gitignore🏁 You Are Now
✔ A published npm package author
✔ CDN-distributed globally
✔ Properly licensed
✔ Professionally structured
🚀 Optional Next Steps
- Add minified build
- Add TypeScript definitions
- Add CI/CD auto publish
- Add automated version bumping
- Convert to ES Module + UMD
Captain.js is now officially live-ready.
